@@ -305,8 +305,13 @@ impl<'a> Parser<'a> {
305305 let removal_span = kw. span . with_hi ( self . token . span . lo ( ) ) ;
306306 let path = self . parse_path ( PathStyle :: Type ) ?;
307307 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+ ) ?;
310315 let err = self . dcx ( ) . create_err ( errors:: TransposeDynOrImpl {
311316 span : kw. span ,
312317 kw : kw. name . as_str ( ) ,
@@ -333,7 +338,13 @@ impl<'a> Parser<'a> {
333338 } else {
334339 let path = self . parse_path ( PathStyle :: Type ) ?;
335340 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+ ) ?
337348 }
338349 }
339350 } else if self . eat_keyword ( exp ! ( Impl ) ) {
@@ -413,9 +424,13 @@ impl<'a> Parser<'a> {
413424 let maybe_bounds = allow_plus == AllowPlus :: Yes && self . token . is_like_plus ( ) ;
414425 match ty. kind {
415426 // `(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+ ) ,
419434 // For `('a) + …`, we know that `'a` in type position already lead to an error being
420435 // emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
421436 // other irrelevant consequential errors.
@@ -495,12 +510,14 @@ impl<'a> Parser<'a> {
495510 path : ast:: Path ,
496511 lo : Span ,
497512 parse_plus : bool ,
513+ parens : ast:: Parens ,
498514 ) -> PResult < ' a , TyKind > {
499515 let poly_trait_ref = PolyTraitRef :: new (
500516 generic_params,
501517 path,
502518 TraitBoundModifiers :: NONE ,
503519 lo. to ( self . prev_token . span ) ,
520+ parens,
504521 ) ;
505522 let bounds = vec ! [ GenericBound :: Trait ( poly_trait_ref) ] ;
506523 self . parse_remaining_bounds ( bounds, parse_plus)
@@ -832,7 +849,7 @@ impl<'a> Parser<'a> {
832849 Ok ( TyKind :: MacCall ( P ( MacCall { path, args : self . parse_delim_args ( ) ? } ) ) )
833850 } else if allow_plus == AllowPlus :: Yes && self . check_plus ( ) {
834851 // `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 )
836853 } else {
837854 // Just a type path.
838855 Ok ( TyKind :: Path ( None , path) )
@@ -897,10 +914,10 @@ impl<'a> Parser<'a> {
897914 fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
898915 let lo = self . token . span ;
899916 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 } ;
901918
902919 let bound = if self . token . is_lifetime ( ) {
903- self . parse_generic_lt_bound ( lo, has_parens ) ?
920+ self . parse_generic_lt_bound ( lo, parens ) ?
904921 } else if self . eat_keyword ( exp ! ( Use ) ) {
905922 // parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
906923 // lifetimes and ident params (including SelfUpper). These are validated later
@@ -909,7 +926,7 @@ impl<'a> Parser<'a> {
909926 let ( args, args_span) = self . parse_precise_capturing_args ( ) ?;
910927 GenericBound :: Use ( args, use_span. to ( args_span) )
911928 } else {
912- self . parse_generic_ty_bound ( lo, has_parens , & leading_token) ?
929+ self . parse_generic_ty_bound ( lo, parens , & leading_token) ?
913930 } ;
914931
915932 Ok ( bound)
@@ -919,10 +936,14 @@ impl<'a> Parser<'a> {
919936 /// ```ebnf
920937 /// LT_BOUND = LIFETIME
921938 /// ```
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 > {
923944 let lt = self . expect_lifetime ( ) ;
924945 let bound = GenericBound :: Outlives ( lt) ;
925- if has_parens {
946+ if let ast :: Parens :: Yes = parens {
926947 // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
927948 // possibly introducing `GenericBound::Paren(P<GenericBound>)`?
928949 self . recover_paren_lifetime ( lo) ?;
@@ -1078,7 +1099,7 @@ impl<'a> Parser<'a> {
10781099 fn parse_generic_ty_bound (
10791100 & mut self ,
10801101 lo : Span ,
1081- has_parens : bool ,
1102+ parens : ast :: Parens ,
10821103 leading_token : & Token ,
10831104 ) -> PResult < ' a , GenericBound > {
10841105 let ( mut lifetime_defs, binder_span) = self . parse_late_bound_lifetime_defs ( ) ?;
@@ -1104,7 +1125,7 @@ impl<'a> Parser<'a> {
11041125 // e.g. `T: for<'a> 'a` or `T: ~const 'a`.
11051126 if self . token . is_lifetime ( ) {
11061127 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 ) ;
11081129 }
11091130
11101131 if let ( more_lifetime_defs, Some ( binder_span) ) = self . parse_late_bound_lifetime_defs ( ) ? {
@@ -1171,7 +1192,7 @@ impl<'a> Parser<'a> {
11711192 self . recover_fn_trait_with_lifetime_params ( & mut path, & mut lifetime_defs) ?;
11721193 }
11731194
1174- if has_parens {
1195+ if let ast :: Parens :: Yes = parens {
11751196 // Someone has written something like `&dyn (Trait + Other)`. The correct code
11761197 // would be `&(dyn Trait + Other)`
11771198 if self . token . is_like_plus ( ) && leading_token. is_keyword ( kw:: Dyn ) {
@@ -1191,7 +1212,7 @@ impl<'a> Parser<'a> {
11911212 }
11921213
11931214 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 ) ;
11951216 Ok ( GenericBound :: Trait ( poly_trait) )
11961217 }
11971218
0 commit comments