@@ -305,8 +305,13 @@ impl<'a> Parser<'a> {
305
305
let removal_span = kw. span . with_hi ( self . token . span . lo ( ) ) ;
306
306
let path = self . parse_path ( PathStyle :: Type ) ?;
307
307
let parse_plus = allow_plus == AllowPlus :: Yes && self . check_plus ( ) ;
308
- let kind =
309
- self . parse_remaining_bounds_path ( lifetime_defs, path, lo, parse_plus) ?;
308
+ let kind = self . parse_remaining_bounds_path (
309
+ lifetime_defs,
310
+ path,
311
+ lo,
312
+ parse_plus,
313
+ ast:: Parens :: No ,
314
+ ) ?;
310
315
let err = self . dcx ( ) . create_err ( errors:: TransposeDynOrImpl {
311
316
span : kw. span ,
312
317
kw : kw. name . as_str ( ) ,
@@ -333,7 +338,13 @@ impl<'a> Parser<'a> {
333
338
} else {
334
339
let path = self . parse_path ( PathStyle :: Type ) ?;
335
340
let parse_plus = allow_plus == AllowPlus :: Yes && self . check_plus ( ) ;
336
- self . parse_remaining_bounds_path ( lifetime_defs, path, lo, parse_plus) ?
341
+ self . parse_remaining_bounds_path (
342
+ lifetime_defs,
343
+ path,
344
+ lo,
345
+ parse_plus,
346
+ ast:: Parens :: No ,
347
+ ) ?
337
348
}
338
349
}
339
350
} else if self . eat_keyword ( exp ! ( Impl ) ) {
@@ -413,9 +424,13 @@ impl<'a> Parser<'a> {
413
424
let maybe_bounds = allow_plus == AllowPlus :: Yes && self . token . is_like_plus ( ) ;
414
425
match ty. kind {
415
426
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
416
- TyKind :: Path ( None , path) if maybe_bounds => {
417
- self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true )
418
- }
427
+ TyKind :: Path ( None , path) if maybe_bounds => self . parse_remaining_bounds_path (
428
+ ThinVec :: new ( ) ,
429
+ path,
430
+ lo,
431
+ true ,
432
+ ast:: Parens :: Yes ,
433
+ ) ,
419
434
// For `('a) + …`, we know that `'a` in type position already lead to an error being
420
435
// emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
421
436
// other irrelevant consequential errors.
@@ -495,12 +510,14 @@ impl<'a> Parser<'a> {
495
510
path : ast:: Path ,
496
511
lo : Span ,
497
512
parse_plus : bool ,
513
+ parens : ast:: Parens ,
498
514
) -> PResult < ' a , TyKind > {
499
515
let poly_trait_ref = PolyTraitRef :: new (
500
516
generic_params,
501
517
path,
502
518
TraitBoundModifiers :: NONE ,
503
519
lo. to ( self . prev_token . span ) ,
520
+ parens,
504
521
) ;
505
522
let bounds = vec ! [ GenericBound :: Trait ( poly_trait_ref) ] ;
506
523
self . parse_remaining_bounds ( bounds, parse_plus)
@@ -832,7 +849,7 @@ impl<'a> Parser<'a> {
832
849
Ok ( TyKind :: MacCall ( P ( MacCall { path, args : self . parse_delim_args ( ) ? } ) ) )
833
850
} else if allow_plus == AllowPlus :: Yes && self . check_plus ( ) {
834
851
// `Trait1 + Trait2 + 'a`
835
- self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true )
852
+ self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true , ast :: Parens :: No )
836
853
} else {
837
854
// Just a type path.
838
855
Ok ( TyKind :: Path ( None , path) )
@@ -897,10 +914,10 @@ impl<'a> Parser<'a> {
897
914
fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
898
915
let lo = self . token . span ;
899
916
let leading_token = self . prev_token ;
900
- let has_parens = self . eat ( exp ! ( OpenParen ) ) ;
917
+ let parens = if self . eat ( exp ! ( OpenParen ) ) { ast :: Parens :: Yes } else { ast :: Parens :: No } ;
901
918
902
919
let bound = if self . token . is_lifetime ( ) {
903
- self . parse_generic_lt_bound ( lo, has_parens ) ?
920
+ self . parse_generic_lt_bound ( lo, parens ) ?
904
921
} else if self . eat_keyword ( exp ! ( Use ) ) {
905
922
// parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
906
923
// lifetimes and ident params (including SelfUpper). These are validated later
@@ -909,7 +926,7 @@ impl<'a> Parser<'a> {
909
926
let ( args, args_span) = self . parse_precise_capturing_args ( ) ?;
910
927
GenericBound :: Use ( args, use_span. to ( args_span) )
911
928
} else {
912
- self . parse_generic_ty_bound ( lo, has_parens , & leading_token) ?
929
+ self . parse_generic_ty_bound ( lo, parens , & leading_token) ?
913
930
} ;
914
931
915
932
Ok ( bound)
@@ -919,10 +936,14 @@ impl<'a> Parser<'a> {
919
936
/// ```ebnf
920
937
/// LT_BOUND = LIFETIME
921
938
/// ```
922
- fn parse_generic_lt_bound ( & mut self , lo : Span , has_parens : bool ) -> PResult < ' a , GenericBound > {
939
+ fn parse_generic_lt_bound (
940
+ & mut self ,
941
+ lo : Span ,
942
+ parens : ast:: Parens ,
943
+ ) -> PResult < ' a , GenericBound > {
923
944
let lt = self . expect_lifetime ( ) ;
924
945
let bound = GenericBound :: Outlives ( lt) ;
925
- if has_parens {
946
+ if let ast :: Parens :: Yes = parens {
926
947
// FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
927
948
// possibly introducing `GenericBound::Paren(P<GenericBound>)`?
928
949
self . recover_paren_lifetime ( lo) ?;
@@ -1078,7 +1099,7 @@ impl<'a> Parser<'a> {
1078
1099
fn parse_generic_ty_bound (
1079
1100
& mut self ,
1080
1101
lo : Span ,
1081
- has_parens : bool ,
1102
+ parens : ast :: Parens ,
1082
1103
leading_token : & Token ,
1083
1104
) -> PResult < ' a , GenericBound > {
1084
1105
let ( mut lifetime_defs, binder_span) = self . parse_late_bound_lifetime_defs ( ) ?;
@@ -1104,7 +1125,7 @@ impl<'a> Parser<'a> {
1104
1125
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
1105
1126
if self . token . is_lifetime ( ) {
1106
1127
let _: ErrorGuaranteed = self . error_lt_bound_with_modifiers ( modifiers, binder_span) ;
1107
- return self . parse_generic_lt_bound ( lo, has_parens ) ;
1128
+ return self . parse_generic_lt_bound ( lo, parens ) ;
1108
1129
}
1109
1130
1110
1131
if let ( more_lifetime_defs, Some ( binder_span) ) = self . parse_late_bound_lifetime_defs ( ) ? {
@@ -1171,7 +1192,7 @@ impl<'a> Parser<'a> {
1171
1192
self . recover_fn_trait_with_lifetime_params ( & mut path, & mut lifetime_defs) ?;
1172
1193
}
1173
1194
1174
- if has_parens {
1195
+ if let ast :: Parens :: Yes = parens {
1175
1196
// Someone has written something like `&dyn (Trait + Other)`. The correct code
1176
1197
// would be `&(dyn Trait + Other)`
1177
1198
if self . token . is_like_plus ( ) && leading_token. is_keyword ( kw:: Dyn ) {
@@ -1191,7 +1212,7 @@ impl<'a> Parser<'a> {
1191
1212
}
1192
1213
1193
1214
let poly_trait =
1194
- PolyTraitRef :: new ( lifetime_defs, path, modifiers, lo. to ( self . prev_token . span ) ) ;
1215
+ PolyTraitRef :: new ( lifetime_defs, path, modifiers, lo. to ( self . prev_token . span ) , parens ) ;
1195
1216
Ok ( GenericBound :: Trait ( poly_trait) )
1196
1217
}
1197
1218
0 commit comments