@@ -1387,7 +1387,7 @@ impl<'a> Parser<'a> {
13871387 None
13881388 } ;
13891389 ( ident, TraitItemKind :: Const ( ty, default) , ast:: Generics :: default ( ) )
1390- } else if self . token . is_path_start ( ) {
1390+ } else if self . token . is_path_start ( ) && ! self . is_extern_non_path ( ) {
13911391 // trait item macro.
13921392 // code copied from parse_macro_use_or_failure... abstraction!
13931393 let prev_span = self . prev_span ;
@@ -4037,6 +4037,10 @@ impl<'a> Parser<'a> {
40374037 self . token . is_keyword ( keywords:: Crate ) && self . look_ahead ( 1 , |t| t != & token:: ModSep )
40384038 }
40394039
4040+ fn is_extern_non_path ( & self ) -> bool {
4041+ self . token . is_keyword ( keywords:: Extern ) && self . look_ahead ( 1 , |t| t != & token:: ModSep )
4042+ }
4043+
40404044 fn eat_auto_trait ( & mut self ) -> bool {
40414045 if self . token . is_keyword ( keywords:: Auto )
40424046 && self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Trait ) )
@@ -4152,10 +4156,12 @@ impl<'a> Parser<'a> {
41524156 // like a path (1 token), but it fact not a path.
41534157 // `union::b::c` - path, `union U { ... }` - not a path.
41544158 // `crate::b::c` - path, `crate struct S;` - not a path.
4159+ // `extern::b::c` - path, `extern crate c;` - not a path.
41554160 } else if self . token . is_path_start ( ) &&
41564161 !self . token . is_qpath_start ( ) &&
41574162 !self . is_union_item ( ) &&
4158- !self . is_crate_vis ( ) {
4163+ !self . is_crate_vis ( ) &&
4164+ !self . is_extern_non_path ( ) {
41594165 let pth = self . parse_path ( PathStyle :: Expr ) ?;
41604166
41614167 if !self . eat ( & token:: Not ) {
@@ -5236,7 +5242,7 @@ impl<'a> Parser<'a> {
52365242 -> PResult < ' a , ( Ident , Vec < ast:: Attribute > , ast:: Generics ,
52375243 ast:: ImplItemKind ) > {
52385244 // code copied from parse_macro_use_or_failure... abstraction!
5239- if self . token . is_path_start ( ) {
5245+ if self . token . is_path_start ( ) && ! self . is_extern_non_path ( ) {
52405246 // Method macro.
52415247
52425248 let prev_span = self . prev_span ;
@@ -6238,7 +6244,8 @@ impl<'a> Parser<'a> {
62386244 return Ok ( Some ( item) ) ;
62396245 }
62406246
6241- if self . eat_keyword ( keywords:: Extern ) {
6247+ if self . check_keyword ( keywords:: Extern ) && self . is_extern_non_path ( ) {
6248+ self . bump ( ) ; // `extern`
62426249 if self . eat_keyword ( keywords:: Crate ) {
62436250 return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
62446251 }
0 commit comments