@@ -1365,18 +1365,15 @@ impl<'a> Parser<'a> {
1365
1365
match ty. node {
1366
1366
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
1367
1367
TyKind :: Path ( None , ref path) if maybe_bounds => {
1368
- self . bump ( ) ; // `+`
1369
- let pt = PolyTraitRef :: new ( Vec :: new ( ) , path. clone ( ) , lo. to ( self . prev_span ) ) ;
1370
- let mut bounds = vec ! [ TraitTyParamBound ( pt, TraitBoundModifier :: None ) ] ;
1371
- bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
1372
- TyKind :: TraitObject ( bounds)
1368
+ self . parse_remaining_bounds ( Vec :: new ( ) , path. clone ( ) , lo, true ) ?
1373
1369
}
1374
1370
TyKind :: TraitObject ( ref bounds)
1375
1371
if maybe_bounds && bounds. len ( ) == 1 && !trailing_plus => {
1376
- self . bump ( ) ; // `+`
1377
- let mut bounds = bounds. clone ( ) ;
1378
- bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
1379
- TyKind :: TraitObject ( bounds)
1372
+ let path = match bounds[ 0 ] {
1373
+ TraitTyParamBound ( ref pt, ..) => pt. trait_ref . path . clone ( ) ,
1374
+ _ => self . bug ( "unexpected lifetime bound" ) ,
1375
+ } ;
1376
+ self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true ) ?
1380
1377
}
1381
1378
// `(TYPE)`
1382
1379
_ => TyKind :: Paren ( P ( ty) )
@@ -1429,11 +1426,8 @@ impl<'a> Parser<'a> {
1429
1426
// Just a type path or bound list (trait object type) starting with a trait.
1430
1427
// `Type`
1431
1428
// `Trait1 + Trait2 + 'a`
1432
- if allow_plus && self . eat ( & token:: BinOp ( token:: Plus ) ) {
1433
- let poly_trait = PolyTraitRef :: new ( Vec :: new ( ) , path, lo. to ( self . prev_span ) ) ;
1434
- let mut bounds = vec ! [ TraitTyParamBound ( poly_trait, TraitBoundModifier :: None ) ] ;
1435
- bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
1436
- TyKind :: TraitObject ( bounds)
1429
+ if allow_plus && self . check ( & token:: BinOp ( token:: Plus ) ) {
1430
+ self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true ) ?
1437
1431
} else {
1438
1432
TyKind :: Path ( None , path)
1439
1433
}
@@ -1451,12 +1445,8 @@ impl<'a> Parser<'a> {
1451
1445
self . parse_ty_bare_fn ( lifetime_defs) ?
1452
1446
} else {
1453
1447
let path = self . parse_path ( PathStyle :: Type ) ?;
1454
- let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, lo. to ( self . prev_span ) ) ;
1455
- let mut bounds = vec ! [ TraitTyParamBound ( poly_trait, TraitBoundModifier :: None ) ] ;
1456
- if allow_plus && self . eat ( & token:: BinOp ( token:: Plus ) ) {
1457
- bounds. append ( & mut self . parse_ty_param_bounds ( ) ?)
1458
- }
1459
- TyKind :: TraitObject ( bounds)
1448
+ let parse_plus = allow_plus && self . check ( & token:: BinOp ( token:: Plus ) ) ;
1449
+ self . parse_remaining_bounds ( lifetime_defs, path, lo, parse_plus) ?
1460
1450
}
1461
1451
} else if self . eat_keyword ( keywords:: Impl ) {
1462
1452
// FIXME: figure out priority of `+` in `impl Trait1 + Trait2` (#34511).
@@ -1479,6 +1469,17 @@ impl<'a> Parser<'a> {
1479
1469
Ok ( P ( ty) )
1480
1470
}
1481
1471
1472
+ fn parse_remaining_bounds ( & mut self , lifetime_defs : Vec < LifetimeDef > , path : ast:: Path ,
1473
+ lo : Span , parse_plus : bool ) -> PResult < ' a , TyKind > {
1474
+ let poly_trait_ref = PolyTraitRef :: new ( lifetime_defs, path, lo. to ( self . prev_span ) ) ;
1475
+ let mut bounds = vec ! [ TraitTyParamBound ( poly_trait_ref, TraitBoundModifier :: None ) ] ;
1476
+ if parse_plus {
1477
+ self . bump ( ) ; // `+`
1478
+ bounds. append ( & mut self . parse_ty_param_bounds ( ) ?) ;
1479
+ }
1480
+ Ok ( TyKind :: TraitObject ( bounds) )
1481
+ }
1482
+
1482
1483
fn maybe_recover_from_bad_type_plus ( & mut self , allow_plus : bool , ty : & Ty ) -> PResult < ' a , ( ) > {
1483
1484
// Do not add `+` to expected tokens.
1484
1485
if !allow_plus || self . token != token:: BinOp ( token:: Plus ) {
0 commit comments