@@ -1387,7 +1387,7 @@ impl<'a> Parser<'a> {
1387
1387
None
1388
1388
} ;
1389
1389
( 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 ( ) {
1391
1391
// trait item macro.
1392
1392
// code copied from parse_macro_use_or_failure... abstraction!
1393
1393
let prev_span = self . prev_span ;
@@ -4037,6 +4037,10 @@ impl<'a> Parser<'a> {
4037
4037
self . token . is_keyword ( keywords:: Crate ) && self . look_ahead ( 1 , |t| t != & token:: ModSep )
4038
4038
}
4039
4039
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
+
4040
4044
fn eat_auto_trait ( & mut self ) -> bool {
4041
4045
if self . token . is_keyword ( keywords:: Auto )
4042
4046
&& self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Trait ) )
@@ -4152,10 +4156,12 @@ impl<'a> Parser<'a> {
4152
4156
// like a path (1 token), but it fact not a path.
4153
4157
// `union::b::c` - path, `union U { ... }` - not a path.
4154
4158
// `crate::b::c` - path, `crate struct S;` - not a path.
4159
+ // `extern::b::c` - path, `extern crate c;` - not a path.
4155
4160
} else if self . token . is_path_start ( ) &&
4156
4161
!self . token . is_qpath_start ( ) &&
4157
4162
!self . is_union_item ( ) &&
4158
- !self . is_crate_vis ( ) {
4163
+ !self . is_crate_vis ( ) &&
4164
+ !self . is_extern_non_path ( ) {
4159
4165
let pth = self . parse_path ( PathStyle :: Expr ) ?;
4160
4166
4161
4167
if !self . eat ( & token:: Not ) {
@@ -5236,7 +5242,7 @@ impl<'a> Parser<'a> {
5236
5242
-> PResult < ' a , ( Ident , Vec < ast:: Attribute > , ast:: Generics ,
5237
5243
ast:: ImplItemKind ) > {
5238
5244
// 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 ( ) {
5240
5246
// Method macro.
5241
5247
5242
5248
let prev_span = self . prev_span ;
@@ -6238,7 +6244,8 @@ impl<'a> Parser<'a> {
6238
6244
return Ok ( Some ( item) ) ;
6239
6245
}
6240
6246
6241
- if self . eat_keyword ( keywords:: Extern ) {
6247
+ if self . check_keyword ( keywords:: Extern ) && self . is_extern_non_path ( ) {
6248
+ self . bump ( ) ; // `extern`
6242
6249
if self . eat_keyword ( keywords:: Crate ) {
6243
6250
return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
6244
6251
}
0 commit comments