File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -4981,18 +4981,27 @@ impl<'a> Parser<'a> {
4981
4981
attrs : Vec < Attribute > )
4982
4982
-> ItemOrViewItem {
4983
4983
4984
+ let span = self . span ;
4984
4985
let ( maybe_path, ident) = match self . token {
4985
4986
token:: IDENT ( ..) => {
4986
4987
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 ) {
4990
4989
let path = self . parse_str ( ) ;
4991
4990
let span = self . span ;
4992
4991
self . obsolete ( span, ObsoleteExternCrateRenaming ) ;
4993
4992
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
+ } ;
4996
5005
self . expect ( & token:: SEMI ) ;
4997
5006
( path, the_ident)
4998
5007
} ,
Original file line number Diff line number Diff line change
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?
You can’t perform that action at this time.
0 commit comments