@@ -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)
@@ -826,7 +843,7 @@ impl<'a> Parser<'a> {
826
843
Ok ( TyKind :: MacCall ( P ( MacCall { path, args : self . parse_delim_args ( ) ? } ) ) )
827
844
} else if allow_plus == AllowPlus :: Yes && self . check_plus ( ) {
828
845
// `Trait1 + Trait2 + 'a`
829
- self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true )
846
+ self . parse_remaining_bounds_path ( ThinVec :: new ( ) , path, lo, true , ast :: Parens :: No )
830
847
} else {
831
848
// Just a type path.
832
849
Ok ( TyKind :: Path ( None , path) )
@@ -892,10 +909,10 @@ impl<'a> Parser<'a> {
892
909
fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
893
910
let lo = self . token . span ;
894
911
let leading_token = self . prev_token ;
895
- let has_parens = self . eat ( exp ! ( OpenParen ) ) ;
912
+ let parens = if self . eat ( exp ! ( OpenParen ) ) { ast :: Parens :: Yes } else { ast :: Parens :: No } ;
896
913
897
914
let bound = if self . token . is_lifetime ( ) {
898
- self . parse_generic_lt_bound ( lo, has_parens ) ?
915
+ self . parse_generic_lt_bound ( lo, parens ) ?
899
916
} else if self . eat_keyword ( exp ! ( Use ) ) {
900
917
// parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
901
918
// lifetimes and ident params (including SelfUpper). These are validated later
@@ -904,7 +921,7 @@ impl<'a> Parser<'a> {
904
921
let ( args, args_span) = self . parse_precise_capturing_args ( ) ?;
905
922
GenericBound :: Use ( args, use_span. to ( args_span) )
906
923
} else {
907
- self . parse_generic_ty_bound ( lo, has_parens , & leading_token) ?
924
+ self . parse_generic_ty_bound ( lo, parens , & leading_token) ?
908
925
} ;
909
926
910
927
Ok ( bound)
@@ -914,10 +931,14 @@ impl<'a> Parser<'a> {
914
931
/// ```ebnf
915
932
/// LT_BOUND = LIFETIME
916
933
/// ```
917
- fn parse_generic_lt_bound ( & mut self , lo : Span , has_parens : bool ) -> PResult < ' a , GenericBound > {
934
+ fn parse_generic_lt_bound (
935
+ & mut self ,
936
+ lo : Span ,
937
+ parens : ast:: Parens ,
938
+ ) -> PResult < ' a , GenericBound > {
918
939
let lt = self . expect_lifetime ( ) ;
919
940
let bound = GenericBound :: Outlives ( lt) ;
920
- if has_parens {
941
+ if let ast :: Parens :: Yes = parens {
921
942
// FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
922
943
// possibly introducing `GenericBound::Paren(P<GenericBound>)`?
923
944
self . recover_paren_lifetime ( lo) ?;
@@ -1090,7 +1111,7 @@ impl<'a> Parser<'a> {
1090
1111
fn parse_generic_ty_bound (
1091
1112
& mut self ,
1092
1113
lo : Span ,
1093
- has_parens : bool ,
1114
+ parens : ast :: Parens ,
1094
1115
leading_token : & Token ,
1095
1116
) -> PResult < ' a , GenericBound > {
1096
1117
let ( mut lifetime_defs, binder_span) = self . parse_late_bound_lifetime_defs ( ) ?;
@@ -1116,7 +1137,7 @@ impl<'a> Parser<'a> {
1116
1137
// e.g. `T: for<'a> 'a` or `T: [const] 'a`.
1117
1138
if self . token . is_lifetime ( ) {
1118
1139
let _: ErrorGuaranteed = self . error_lt_bound_with_modifiers ( modifiers, binder_span) ;
1119
- return self . parse_generic_lt_bound ( lo, has_parens ) ;
1140
+ return self . parse_generic_lt_bound ( lo, parens ) ;
1120
1141
}
1121
1142
1122
1143
if let ( more_lifetime_defs, Some ( binder_span) ) = self . parse_late_bound_lifetime_defs ( ) ? {
@@ -1183,7 +1204,7 @@ impl<'a> Parser<'a> {
1183
1204
self . recover_fn_trait_with_lifetime_params ( & mut path, & mut lifetime_defs) ?;
1184
1205
}
1185
1206
1186
- if has_parens {
1207
+ if let ast :: Parens :: Yes = parens {
1187
1208
// Someone has written something like `&dyn (Trait + Other)`. The correct code
1188
1209
// would be `&(dyn Trait + Other)`
1189
1210
if self . token . is_like_plus ( ) && leading_token. is_keyword ( kw:: Dyn ) {
@@ -1203,7 +1224,7 @@ impl<'a> Parser<'a> {
1203
1224
}
1204
1225
1205
1226
let poly_trait =
1206
- PolyTraitRef :: new ( lifetime_defs, path, modifiers, lo. to ( self . prev_token . span ) ) ;
1227
+ PolyTraitRef :: new ( lifetime_defs, path, modifiers, lo. to ( self . prev_token . span ) , parens ) ;
1207
1228
Ok ( GenericBound :: Trait ( poly_trait) )
1208
1229
}
1209
1230
0 commit comments