@@ -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) 
@@ -826,7 +843,7 @@ impl<'a> Parser<'a> {
826843            Ok ( TyKind :: MacCall ( P ( MacCall  {  path,  args :  self . parse_delim_args ( ) ? } ) ) ) 
827844        }  else  if  allow_plus == AllowPlus :: Yes  && self . check_plus ( )  { 
828845            // `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 ) 
830847        }  else  { 
831848            // Just a type path. 
832849            Ok ( TyKind :: Path ( None ,  path) ) 
@@ -892,10 +909,10 @@ impl<'a> Parser<'a> {
892909     fn  parse_generic_bound ( & mut  self )  -> PResult < ' a ,  GenericBound >  { 
893910        let  lo = self . token . span ; 
894911        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   } ; 
896913
897914        let  bound = if  self . token . is_lifetime ( )  { 
898-             self . parse_generic_lt_bound ( lo,  has_parens ) ?
915+             self . parse_generic_lt_bound ( lo,  parens ) ?
899916        }  else  if  self . eat_keyword ( exp ! ( Use ) )  { 
900917            // parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of 
901918            // lifetimes and ident params (including SelfUpper). These are validated later 
@@ -904,7 +921,7 @@ impl<'a> Parser<'a> {
904921            let  ( args,  args_span)  = self . parse_precise_capturing_args ( ) ?; 
905922            GenericBound :: Use ( args,  use_span. to ( args_span) ) 
906923        }  else  { 
907-             self . parse_generic_ty_bound ( lo,  has_parens ,  & leading_token) ?
924+             self . parse_generic_ty_bound ( lo,  parens ,  & leading_token) ?
908925        } ; 
909926
910927        Ok ( bound) 
@@ -914,10 +931,14 @@ impl<'a> Parser<'a> {
914931     /// ```ebnf 
915932     /// LT_BOUND = LIFETIME 
916933     /// ``` 
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 >  { 
918939        let  lt = self . expect_lifetime ( ) ; 
919940        let  bound = GenericBound :: Outlives ( lt) ; 
920-         if  has_parens  { 
941+         if  let  ast :: Parens :: Yes  = parens  { 
921942            // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead, 
922943            // possibly introducing `GenericBound::Paren(P<GenericBound>)`? 
923944            self . recover_paren_lifetime ( lo) ?; 
@@ -1090,7 +1111,7 @@ impl<'a> Parser<'a> {
10901111     fn  parse_generic_ty_bound ( 
10911112        & mut  self , 
10921113        lo :  Span , 
1093-         has_parens :   bool , 
1114+         parens :  ast :: Parens , 
10941115        leading_token :  & Token , 
10951116    )  -> PResult < ' a ,  GenericBound >  { 
10961117        let  ( mut  lifetime_defs,  binder_span)  = self . parse_late_bound_lifetime_defs ( ) ?; 
@@ -1116,7 +1137,7 @@ impl<'a> Parser<'a> {
11161137        // e.g. `T: for<'a> 'a` or `T: [const] 'a`. 
11171138        if  self . token . is_lifetime ( )  { 
11181139            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 ) ; 
11201141        } 
11211142
11221143        if  let  ( more_lifetime_defs,  Some ( binder_span) )  = self . parse_late_bound_lifetime_defs ( ) ? { 
@@ -1183,7 +1204,7 @@ impl<'a> Parser<'a> {
11831204            self . recover_fn_trait_with_lifetime_params ( & mut  path,  & mut  lifetime_defs) ?; 
11841205        } 
11851206
1186-         if  has_parens  { 
1207+         if  let  ast :: Parens :: Yes  = parens  { 
11871208            // Someone has written something like `&dyn (Trait + Other)`. The correct code 
11881209            // would be `&(dyn Trait + Other)` 
11891210            if  self . token . is_like_plus ( )  && leading_token. is_keyword ( kw:: Dyn )  { 
@@ -1203,7 +1224,7 @@ impl<'a> Parser<'a> {
12031224        } 
12041225
12051226        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 ) ; 
12071228        Ok ( GenericBound :: Trait ( poly_trait) ) 
12081229    } 
12091230
0 commit comments