@@ -1467,7 +1467,7 @@ impl<'a> Parser<'a> {
1467
1467
1468
1468
// Parse a type
1469
1469
pub fn parse_ty ( & mut self ) -> PResult < ' a , P < Ty > > {
1470
- self . parse_ty_common ( true )
1470
+ self . parse_ty_common ( true , true )
1471
1471
}
1472
1472
1473
1473
/// Parse a type in restricted contexts where `+` is not permitted.
@@ -1476,10 +1476,11 @@ impl<'a> Parser<'a> {
1476
1476
/// Example 2: `value1 as TYPE + value2`
1477
1477
/// `+` is prohibited to avoid interactions with expression grammar.
1478
1478
fn parse_ty_no_plus ( & mut self ) -> PResult < ' a , P < Ty > > {
1479
- self . parse_ty_common ( false )
1479
+ self . parse_ty_common ( false , true )
1480
1480
}
1481
1481
1482
- fn parse_ty_common ( & mut self , allow_plus : bool ) -> PResult < ' a , P < Ty > > {
1482
+ fn parse_ty_common ( & mut self , allow_plus : bool , allow_qpath_recovery : bool )
1483
+ -> PResult < ' a , P < Ty > > {
1483
1484
maybe_whole ! ( self , NtTy , |x| x) ;
1484
1485
1485
1486
let lo = self . span ;
@@ -1612,7 +1613,7 @@ impl<'a> Parser<'a> {
1612
1613
1613
1614
// Try to recover from use of `+` with incorrect priority.
1614
1615
self . maybe_recover_from_bad_type_plus ( allow_plus, & ty) ?;
1615
- let ty = self . maybe_recover_from_bad_qpath ( ty) ?;
1616
+ let ty = self . maybe_recover_from_bad_qpath ( ty, allow_qpath_recovery ) ?;
1616
1617
1617
1618
Ok ( P ( ty) )
1618
1619
}
@@ -1668,9 +1669,10 @@ impl<'a> Parser<'a> {
1668
1669
}
1669
1670
1670
1671
// Try to recover from associated item paths like `[T]::AssocItem`/`(T, U)::AssocItem`.
1671
- fn maybe_recover_from_bad_qpath < T : RecoverQPath > ( & mut self , base : T ) -> PResult < ' a , T > {
1672
+ fn maybe_recover_from_bad_qpath < T : RecoverQPath > ( & mut self , base : T , allow_recovery : bool )
1673
+ -> PResult < ' a , T > {
1672
1674
// Do not add `::` to expected tokens.
1673
- if self . token != token:: ModSep {
1675
+ if !allow_recovery || self . token != token:: ModSep {
1674
1676
return Ok ( base) ;
1675
1677
}
1676
1678
let ty = match base. to_ty ( ) {
@@ -2004,7 +2006,7 @@ impl<'a> Parser<'a> {
2004
2006
|p| p. parse_ty ( ) ) ?;
2005
2007
self . bump ( ) ; // `)`
2006
2008
let output = if self . eat ( & token:: RArrow ) {
2007
- Some ( self . parse_ty_no_plus ( ) ?)
2009
+ Some ( self . parse_ty_common ( false , false ) ?)
2008
2010
} else {
2009
2011
None
2010
2012
} ;
@@ -2411,7 +2413,7 @@ impl<'a> Parser<'a> {
2411
2413
}
2412
2414
2413
2415
let expr = Expr { node : ex, span : lo. to ( hi) , id : ast:: DUMMY_NODE_ID , attrs } ;
2414
- let expr = self . maybe_recover_from_bad_qpath ( expr) ?;
2416
+ let expr = self . maybe_recover_from_bad_qpath ( expr, true ) ?;
2415
2417
2416
2418
return Ok ( P ( expr) ) ;
2417
2419
}
@@ -3778,7 +3780,7 @@ impl<'a> Parser<'a> {
3778
3780
}
3779
3781
3780
3782
let pat = Pat { node : pat, span : lo. to ( self . prev_span ) , id : ast:: DUMMY_NODE_ID } ;
3781
- let pat = self . maybe_recover_from_bad_qpath ( pat) ?;
3783
+ let pat = self . maybe_recover_from_bad_qpath ( pat, true ) ?;
3782
3784
3783
3785
Ok ( P ( pat) )
3784
3786
}
0 commit comments