Skip to content

Commit a6e0c76

Browse files
committed
auto merge of #17757 : gamazeps/rust/issue17709, r=alexcrichton
I did not put the crate name in the error note, if that's necessary I'll look into it. Closes #17709
2 parents ff61b74 + 0af88e3 commit a6e0c76

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,18 +4980,27 @@ impl<'a> Parser<'a> {
49804980
attrs: Vec<Attribute> )
49814981
-> ItemOrViewItem {
49824982

4983+
let span = self.span;
49834984
let (maybe_path, ident) = match self.token {
49844985
token::IDENT(..) => {
49854986
let the_ident = self.parse_ident();
4986-
self.expect_one_of(&[], &[token::EQ, token::SEMI]);
4987-
let path = if self.token == token::EQ {
4988-
self.bump();
4987+
let path = if self.eat(&token::EQ) {
49894988
let path = self.parse_str();
49904989
let span = self.span;
49914990
self.obsolete(span, ObsoleteExternCrateRenaming);
49924991
Some(path)
4993-
} else {None};
4994-
4992+
} else if self.eat_keyword(keywords::As) {
4993+
// skip the ident if there is one
4994+
if is_ident(&self.token) { self.bump(); }
4995+
4996+
self.span_err(span,
4997+
format!("expected `;`, found `as`; perhaps you meant \
4998+
to enclose the crate name `{}` in a string?",
4999+
the_ident.as_str()).as_slice());
5000+
None
5001+
} else {
5002+
None
5003+
};
49955004
self.expect(&token::SEMI);
49965005
(path, the_ident)
49975006
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that the proper help is displayed in the error message
12+
13+
extern crate foo as bar;
14+
//~^ ERROR expected `;`, found `as`; perhaps you meant to enclose the crate name `foo` in a string?

src/test/compile-fail/extern-foreign-crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
// Verifies that the expected token errors for `extern crate` are
1212
// raised
1313

14-
extern crate foo {} //~ERROR expected one of `=`, `;`, found `{`
14+
extern crate foo {} //~ERROR expected `;`, found `{`

0 commit comments

Comments
 (0)