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> {
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 } ,
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