Skip to content

Commit e69f2ab

Browse files
author
Felix Raimundo
committed
Changed extern crate foo as bar; error message
Closes #17709
1 parent ae81c89 commit e69f2ab

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/libsyntax/parse/parser.rs

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

4984+
let span = self.span;
49844985
let (maybe_path, ident) = match self.token {
49854986
token::IDENT(..) => {
49864987
let the_ident = self.parse_ident();
4987-
self.expect_one_of(&[], &[token::EQ, token::SEMI]);
4988-
let path = if self.token == token::EQ {
4989-
self.bump();
4988+
let path = if self.eat(&token::EQ) {
49904989
let path = self.parse_str();
49914990
let span = self.span;
49924991
self.obsolete(span, ObsoleteExternCrateRenaming);
49934992
Some(path)
4994-
} else {None};
4995-
4993+
} else if self.eat_keyword(keywords::As) {
4994+
// skip the ident if there is one
4995+
if is_ident(&self.token) { self.bump(); }
4996+
4997+
self.span_err(span,
4998+
format!("expected `;`, found `as`; perhaps you meant \
4999+
to enclose the crate name `{}` in a string?",
5000+
the_ident.as_str()).as_slice());
5001+
None
5002+
} else {
5003+
None
5004+
};
49965005
self.expect(&token::SEMI);
49975006
(path, the_ident)
49985007
},
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?

0 commit comments

Comments
 (0)