@@ -901,6 +901,19 @@ impl<'a> Parser<'a> {
901901 _ => false ,
902902 }
903903 }
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+ }
904917
905918 /// Expect and consume an `&`. If `&&` is seen, replace it with a single
906919 /// `&` and continue. If an `&` is not seen, signal an error.
@@ -1533,7 +1546,7 @@ impl<'a> Parser<'a> {
15331546
15341547 if ts. len ( ) == 1 && !last_comma {
15351548 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 ( ) ;
15371550 match ty. node {
15381551 // `(TY_BOUND_NOPAREN) + BOUND + ...`.
15391552 TyKind :: Path ( None , ref path) if maybe_bounds => {
@@ -1602,7 +1615,7 @@ impl<'a> Parser<'a> {
16021615 self . parse_ty_bare_fn ( lifetime_defs) ?
16031616 } else {
16041617 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 ( ) ;
16061619 self . parse_remaining_bounds ( lifetime_defs, path, lo, parse_plus) ?
16071620 }
16081621 } else if self . eat_keyword ( keywords:: Impl ) {
@@ -1619,7 +1632,7 @@ impl<'a> Parser<'a> {
16191632 impl_dyn_multi = bounds. len ( ) > 1 || self . prev_token_kind == PrevTokenKind :: Plus ;
16201633 TyKind :: TraitObject ( bounds, TraitObjectSyntax :: Dyn )
16211634 } 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 ( ) ) {
16231636 // Bound list (trait object type)
16241637 TyKind :: TraitObject ( self . parse_ty_param_bounds_common ( allow_plus) ?,
16251638 TraitObjectSyntax :: None )
@@ -1639,7 +1652,7 @@ impl<'a> Parser<'a> {
16391652 // Just a type path or bound list (trait object type) starting with a trait.
16401653 // `Type`
16411654 // `Trait1 + Trait2 + 'a`
1642- if allow_plus && self . check ( & token :: BinOp ( token :: Plus ) ) {
1655+ if allow_plus && self . check_plus ( ) {
16431656 self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true ) ?
16441657 } else {
16451658 TyKind :: Path ( None , path)
@@ -1666,7 +1679,7 @@ impl<'a> Parser<'a> {
16661679 let poly_trait_ref = PolyTraitRef :: new ( generic_params, path, lo. to ( self . prev_span ) ) ;
16671680 let mut bounds = vec ! [ TraitTyParamBound ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
16681681 if parse_plus {
1669- self . bump ( ) ; // `+`
1682+ self . eat_plus ( ) ; // `+` or `+=` gets split and `+` is discarded
16701683 bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
16711684 }
16721685 Ok ( TyKind :: TraitObject ( bounds, TraitObjectSyntax :: None ) )
@@ -1687,7 +1700,7 @@ impl<'a> Parser<'a> {
16871700
16881701 fn maybe_recover_from_bad_type_plus ( & mut self , allow_plus : bool , ty : & Ty ) -> PResult < ' a , ( ) > {
16891702 // 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 ( ) {
16911704 return Ok ( ( ) )
16921705 }
16931706
@@ -4841,7 +4854,7 @@ impl<'a> Parser<'a> {
48414854 while self . check_lifetime ( ) {
48424855 lifetimes. push ( self . expect_lifetime ( ) ) ;
48434856
4844- if !self . eat ( & token :: BinOp ( token :: Plus ) ) {
4857+ if !self . eat_plus ( ) {
48454858 break
48464859 }
48474860 }
@@ -4987,7 +5000,7 @@ impl<'a> Parser<'a> {
49875000 let mut seen_type = false ;
49885001 let mut seen_binding = false ;
49895002 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 ( ) ) {
49915004 // Parse lifetime argument.
49925005 lifetimes. push ( self . expect_lifetime ( ) ) ;
49935006 if seen_type || seen_binding {
@@ -5056,7 +5069,7 @@ impl<'a> Parser<'a> {
50565069
50575070 loop {
50585071 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 ( ) ) {
50605073 let lifetime = self . expect_lifetime ( ) ;
50615074 // Bounds starting with a colon are mandatory, but possibly empty.
50625075 self . expect ( & token:: Colon ) ?;
0 commit comments