@@ -901,6 +901,19 @@ impl<'a> Parser<'a> {
901
901
_ => false ,
902
902
}
903
903
}
904
+
905
+
906
+ /// Checks to see if the next token is either `+` or `+=`.
907
+ /// Otherwise returns false.
908
+ fn check_plus ( & mut self ) -> bool {
909
+ if self . token . is_like_plus ( ) {
910
+ true
911
+ }
912
+ else {
913
+ self . expected_tokens . push ( TokenType :: Token ( token:: BinOp ( token:: Plus ) ) ) ;
914
+ false
915
+ }
916
+ }
904
917
905
918
/// Expect and consume an `&`. If `&&` is seen, replace it with a single
906
919
/// `&` and continue. If an `&` is not seen, signal an error.
@@ -1533,7 +1546,7 @@ impl<'a> Parser<'a> {
1533
1546
1534
1547
if ts. len ( ) == 1 && !last_comma {
1535
1548
let ty = ts. into_iter ( ) . nth ( 0 ) . unwrap ( ) . into_inner ( ) ;
1536
- let maybe_bounds = allow_plus && self . token == token :: BinOp ( token :: Plus ) ;
1549
+ let maybe_bounds = allow_plus && self . check_plus ( ) ;
1537
1550
match ty. node {
1538
1551
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
1539
1552
TyKind :: Path ( None , ref path) if maybe_bounds => {
@@ -1602,7 +1615,7 @@ impl<'a> Parser<'a> {
1602
1615
self . parse_ty_bare_fn ( lifetime_defs) ?
1603
1616
} else {
1604
1617
let path = self . parse_path ( PathStyle :: Type ) ?;
1605
- let parse_plus = allow_plus && self . check ( & token :: BinOp ( token :: Plus ) ) ;
1618
+ let parse_plus = allow_plus && self . check_plus ( ) ;
1606
1619
self . parse_remaining_bounds ( lifetime_defs, path, lo, parse_plus) ?
1607
1620
}
1608
1621
} else if self . eat_keyword ( keywords:: Impl ) {
@@ -1619,7 +1632,7 @@ impl<'a> Parser<'a> {
1619
1632
impl_dyn_multi = bounds. len ( ) > 1 || self . prev_token_kind == PrevTokenKind :: Plus ;
1620
1633
TyKind :: TraitObject ( bounds, TraitObjectSyntax :: Dyn )
1621
1634
} else if self . check ( & token:: Question ) ||
1622
- self . check_lifetime ( ) && self . look_ahead ( 1 , |t| t == & token :: BinOp ( token :: Plus ) ) {
1635
+ self . check_lifetime ( ) && self . look_ahead ( 1 , |t| t. is_like_plus ( ) ) {
1623
1636
// Bound list (trait object type)
1624
1637
TyKind :: TraitObject ( self . parse_ty_param_bounds_common ( allow_plus) ?,
1625
1638
TraitObjectSyntax :: None )
@@ -1639,7 +1652,7 @@ impl<'a> Parser<'a> {
1639
1652
// Just a type path or bound list (trait object type) starting with a trait.
1640
1653
// `Type`
1641
1654
// `Trait1 + Trait2 + 'a`
1642
- if allow_plus && self . check ( & token :: BinOp ( token :: Plus ) ) {
1655
+ if allow_plus && self . check_plus ( ) {
1643
1656
self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true ) ?
1644
1657
} else {
1645
1658
TyKind :: Path ( None , path)
@@ -1666,7 +1679,7 @@ impl<'a> Parser<'a> {
1666
1679
let poly_trait_ref = PolyTraitRef :: new ( generic_params, path, lo. to ( self . prev_span ) ) ;
1667
1680
let mut bounds = vec ! [ TraitTyParamBound ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
1668
1681
if parse_plus {
1669
- self . bump ( ) ; // `+`
1682
+ self . eat_plus ( ) ; // `+` or `+=` gets split and `+` is discarded
1670
1683
bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
1671
1684
}
1672
1685
Ok ( TyKind :: TraitObject ( bounds, TraitObjectSyntax :: None ) )
@@ -1687,7 +1700,7 @@ impl<'a> Parser<'a> {
1687
1700
1688
1701
fn maybe_recover_from_bad_type_plus ( & mut self , allow_plus : bool , ty : & Ty ) -> PResult < ' a , ( ) > {
1689
1702
// Do not add `+` to expected tokens.
1690
- if !allow_plus || self . token != token :: BinOp ( token :: Plus ) {
1703
+ if !allow_plus || ! self . token . is_like_plus ( ) {
1691
1704
return Ok ( ( ) )
1692
1705
}
1693
1706
@@ -4841,7 +4854,7 @@ impl<'a> Parser<'a> {
4841
4854
while self . check_lifetime ( ) {
4842
4855
lifetimes. push ( self . expect_lifetime ( ) ) ;
4843
4856
4844
- if !self . eat ( & token :: BinOp ( token :: Plus ) ) {
4857
+ if !self . eat_plus ( ) {
4845
4858
break
4846
4859
}
4847
4860
}
@@ -4987,7 +5000,7 @@ impl<'a> Parser<'a> {
4987
5000
let mut seen_type = false ;
4988
5001
let mut seen_binding = false ;
4989
5002
loop {
4990
- if self . check_lifetime ( ) && self . look_ahead ( 1 , |t| t != & token :: BinOp ( token :: Plus ) ) {
5003
+ if self . check_lifetime ( ) && self . look_ahead ( 1 , |t| !t . is_like_plus ( ) ) {
4991
5004
// Parse lifetime argument.
4992
5005
lifetimes. push ( self . expect_lifetime ( ) ) ;
4993
5006
if seen_type || seen_binding {
@@ -5056,7 +5069,7 @@ impl<'a> Parser<'a> {
5056
5069
5057
5070
loop {
5058
5071
let lo = self . span ;
5059
- if self . check_lifetime ( ) && self . look_ahead ( 1 , |t| t != & token :: BinOp ( token :: Plus ) ) {
5072
+ if self . check_lifetime ( ) && self . look_ahead ( 1 , |t| !t . is_like_plus ( ) ) {
5060
5073
let lifetime = self . expect_lifetime ( ) ;
5061
5074
// Bounds starting with a colon are mandatory, but possibly empty.
5062
5075
self . expect ( & token:: Colon ) ?;
0 commit comments