@@ -3620,7 +3620,7 @@ impl<'a> Parser<'a> {
3620
3620
// Parse box pat
3621
3621
let subpat = self . parse_pat ( ) ?;
3622
3622
pat = PatKind :: Box ( subpat) ;
3623
- } else if self . token . is_ident ( ) && self . token . is_path_start ( ) &&
3623
+ } else if self . token . is_ident ( ) && ! self . token . is_any_keyword ( ) &&
3624
3624
self . look_ahead ( 1 , |t| match * t {
3625
3625
token:: OpenDelim ( token:: Paren ) | token:: OpenDelim ( token:: Brace ) |
3626
3626
token:: DotDotDot | token:: ModSep | token:: Not => false ,
@@ -3871,6 +3871,11 @@ impl<'a> Parser<'a> {
3871
3871
} )
3872
3872
}
3873
3873
3874
+ fn is_union_item ( & mut self ) -> bool {
3875
+ self . token . is_keyword ( keywords:: Union ) &&
3876
+ self . look_ahead ( 1 , |t| t. is_ident ( ) && !t. is_any_keyword ( ) )
3877
+ }
3878
+
3874
3879
fn parse_stmt_without_recovery ( & mut self ,
3875
3880
macro_legacy_warnings : bool )
3876
3881
-> PResult < ' a , Option < Stmt > > {
@@ -3885,10 +3890,10 @@ impl<'a> Parser<'a> {
3885
3890
node : StmtKind :: Local ( self . parse_local ( attrs. into ( ) ) ?) ,
3886
3891
span : mk_sp ( lo, self . prev_span . hi ) ,
3887
3892
}
3888
- } else if self . token . is_path_start ( ) && self . token != token :: Lt && {
3889
- ! self . check_keyword ( keywords :: Union ) ||
3890
- self . look_ahead ( 1 , |t| * t == token :: Not || * t == token:: ModSep )
3891
- } {
3893
+ // Starts like a simple path, but not a union item.
3894
+ } else if self . token . is_path_start ( ) &&
3895
+ ! self . token . is_qpath_start ( ) &&
3896
+ ! self . is_union_item ( ) {
3892
3897
let pth = self . parse_path ( PathStyle :: Expr ) ?;
3893
3898
3894
3899
if !self . eat ( & token:: Not ) {
@@ -4599,6 +4604,10 @@ impl<'a> Parser<'a> {
4599
4604
token:: Ident ( ident) => { this. bump ( ) ; codemap:: respan ( this. prev_span , ident) }
4600
4605
_ => unreachable ! ( )
4601
4606
} ;
4607
+ let isolated_self = |this : & mut Self , n| {
4608
+ this. look_ahead ( n, |t| t. is_keyword ( keywords:: SelfValue ) ) &&
4609
+ this. look_ahead ( n + 1 , |t| t != & token:: ModSep )
4610
+ } ;
4602
4611
4603
4612
// Parse optional self parameter of a method.
4604
4613
// Only a limited set of initial token sequences is considered self parameters, anything
@@ -4611,22 +4620,22 @@ impl<'a> Parser<'a> {
4611
4620
// &'lt self
4612
4621
// &'lt mut self
4613
4622
// ¬_self
4614
- if self . look_ahead ( 1 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4623
+ if isolated_self ( self , 1 ) {
4615
4624
self . bump ( ) ;
4616
4625
( SelfKind :: Region ( None , Mutability :: Immutable ) , expect_ident ( self ) )
4617
4626
} else if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Mut ) ) &&
4618
- self . look_ahead ( 2 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4627
+ isolated_self ( self , 2 ) {
4619
4628
self . bump ( ) ;
4620
4629
self . bump ( ) ;
4621
4630
( SelfKind :: Region ( None , Mutability :: Mutable ) , expect_ident ( self ) )
4622
4631
} else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) &&
4623
- self . look_ahead ( 2 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4632
+ isolated_self ( self , 2 ) {
4624
4633
self . bump ( ) ;
4625
4634
let lt = self . parse_lifetime ( ) ?;
4626
4635
( SelfKind :: Region ( Some ( lt) , Mutability :: Immutable ) , expect_ident ( self ) )
4627
4636
} else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) &&
4628
4637
self . look_ahead ( 2 , |t| t. is_keyword ( keywords:: Mut ) ) &&
4629
- self . look_ahead ( 3 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4638
+ isolated_self ( self , 3 ) {
4630
4639
self . bump ( ) ;
4631
4640
let lt = self . parse_lifetime ( ) ?;
4632
4641
self . bump ( ) ;
@@ -4641,12 +4650,12 @@ impl<'a> Parser<'a> {
4641
4650
// *mut self
4642
4651
// *not_self
4643
4652
// Emit special error for `self` cases.
4644
- if self . look_ahead ( 1 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4653
+ if isolated_self ( self , 1 ) {
4645
4654
self . bump ( ) ;
4646
4655
self . span_err ( self . span , "cannot pass `self` by raw pointer" ) ;
4647
4656
( SelfKind :: Value ( Mutability :: Immutable ) , expect_ident ( self ) )
4648
4657
} else if self . look_ahead ( 1 , |t| t. is_mutability ( ) ) &&
4649
- self . look_ahead ( 2 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4658
+ isolated_self ( self , 2 ) {
4650
4659
self . bump ( ) ;
4651
4660
self . bump ( ) ;
4652
4661
self . span_err ( self . span , "cannot pass `self` by raw pointer" ) ;
@@ -4656,7 +4665,7 @@ impl<'a> Parser<'a> {
4656
4665
}
4657
4666
}
4658
4667
token:: Ident ( ..) => {
4659
- if self . token . is_keyword ( keywords :: SelfValue ) {
4668
+ if isolated_self ( self , 0 ) {
4660
4669
// self
4661
4670
// self: TYPE
4662
4671
let eself_ident = expect_ident ( self ) ;
@@ -4667,7 +4676,7 @@ impl<'a> Parser<'a> {
4667
4676
( SelfKind :: Value ( Mutability :: Immutable ) , eself_ident)
4668
4677
}
4669
4678
} else if self . token . is_keyword ( keywords:: Mut ) &&
4670
- self . look_ahead ( 1 , |t| t . is_keyword ( keywords :: SelfValue ) ) {
4679
+ isolated_self ( self , 1 ) {
4671
4680
// mut self
4672
4681
// mut self: TYPE
4673
4682
self . bump ( ) ;
@@ -5958,8 +5967,7 @@ impl<'a> Parser<'a> {
5958
5967
maybe_append ( attrs, extra_attrs) ) ;
5959
5968
return Ok ( Some ( item) ) ;
5960
5969
}
5961
- if self . check_keyword ( keywords:: Union ) &&
5962
- self . look_ahead ( 1 , |t| t. is_ident ( ) && !t. is_any_keyword ( ) ) {
5970
+ if self . is_union_item ( ) {
5963
5971
// UNION ITEM
5964
5972
self . bump ( ) ;
5965
5973
let ( ident, item_, extra_attrs) = self . parse_item_union ( ) ?;
0 commit comments