@@ -914,10 +914,10 @@ impl<'a> Parser<'a> {
914
914
fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
915
915
let lo = self . token . span ;
916
916
let leading_token = self . prev_token ;
917
- let has_parens = self . eat ( exp ! ( OpenParen ) ) ;
917
+ let parens = if self . eat ( exp ! ( OpenParen ) ) { ast :: Parens :: Yes } else { ast :: Parens :: No } ;
918
918
919
919
let bound = if self . token . is_lifetime ( ) {
920
- self . parse_generic_lt_bound ( lo, has_parens ) ?
920
+ self . parse_generic_lt_bound ( lo, parens ) ?
921
921
} else if self . eat_keyword ( exp ! ( Use ) ) {
922
922
// parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
923
923
// lifetimes and ident params (including SelfUpper). These are validated later
@@ -926,7 +926,7 @@ impl<'a> Parser<'a> {
926
926
let ( args, args_span) = self . parse_precise_capturing_args ( ) ?;
927
927
GenericBound :: Use ( args, use_span. to ( args_span) )
928
928
} else {
929
- self . parse_generic_ty_bound ( lo, has_parens , & leading_token) ?
929
+ self . parse_generic_ty_bound ( lo, parens , & leading_token) ?
930
930
} ;
931
931
932
932
Ok ( bound)
@@ -936,10 +936,14 @@ impl<'a> Parser<'a> {
936
936
/// ```ebnf
937
937
/// LT_BOUND = LIFETIME
938
938
/// ```
939
- 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 > {
940
944
let lt = self . expect_lifetime ( ) ;
941
945
let bound = GenericBound :: Outlives ( lt) ;
942
- if has_parens {
946
+ if let ast :: Parens :: Yes = parens {
943
947
// FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
944
948
// possibly introducing `GenericBound::Paren(P<GenericBound>)`?
945
949
self . recover_paren_lifetime ( lo) ?;
@@ -1095,7 +1099,7 @@ impl<'a> Parser<'a> {
1095
1099
fn parse_generic_ty_bound (
1096
1100
& mut self ,
1097
1101
lo : Span ,
1098
- has_parens : bool ,
1102
+ parens : ast :: Parens ,
1099
1103
leading_token : & Token ,
1100
1104
) -> PResult < ' a , GenericBound > {
1101
1105
let ( mut lifetime_defs, binder_span) = self . parse_late_bound_lifetime_defs ( ) ?;
@@ -1121,7 +1125,7 @@ impl<'a> Parser<'a> {
1121
1125
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
1122
1126
if self . token . is_lifetime ( ) {
1123
1127
let _: ErrorGuaranteed = self . error_lt_bound_with_modifiers ( modifiers, binder_span) ;
1124
- return self . parse_generic_lt_bound ( lo, has_parens ) ;
1128
+ return self . parse_generic_lt_bound ( lo, parens ) ;
1125
1129
}
1126
1130
1127
1131
if let ( more_lifetime_defs, Some ( binder_span) ) = self . parse_late_bound_lifetime_defs ( ) ? {
@@ -1188,7 +1192,7 @@ impl<'a> Parser<'a> {
1188
1192
self . recover_fn_trait_with_lifetime_params ( & mut path, & mut lifetime_defs) ?;
1189
1193
}
1190
1194
1191
- if has_parens {
1195
+ if let ast :: Parens :: Yes = parens {
1192
1196
// Someone has written something like `&dyn (Trait + Other)`. The correct code
1193
1197
// would be `&(dyn Trait + Other)`
1194
1198
if self . token . is_like_plus ( ) && leading_token. is_keyword ( kw:: Dyn ) {
@@ -1207,13 +1211,12 @@ impl<'a> Parser<'a> {
1207
1211
}
1208
1212
}
1209
1213
1210
- let grouping = if has_parens { ast:: Parens :: Yes } else { ast:: Parens :: No } ;
1211
1214
let poly_trait = PolyTraitRef :: new (
1212
1215
lifetime_defs,
1213
1216
path,
1214
1217
modifiers,
1215
1218
lo. to ( self . prev_token . span ) ,
1216
- grouping ,
1219
+ parens ,
1217
1220
) ;
1218
1221
Ok ( GenericBound :: Trait ( poly_trait) )
1219
1222
}
0 commit comments