Skip to content

Commit 5347261

Browse files
committed
Propagate use of Parens
1 parent 5f07fd2 commit 5347261

File tree

1 file changed

+13
-10
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+13
-10
lines changed

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,10 @@ impl<'a> Parser<'a> {
914914
fn parse_generic_bound(&mut self) -> PResult<'a, GenericBound> {
915915
let lo = self.token.span;
916916
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 };
918918

919919
let bound = if self.token.is_lifetime() {
920-
self.parse_generic_lt_bound(lo, has_parens)?
920+
self.parse_generic_lt_bound(lo, parens)?
921921
} else if self.eat_keyword(exp!(Use)) {
922922
// parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
923923
// lifetimes and ident params (including SelfUpper). These are validated later
@@ -926,7 +926,7 @@ impl<'a> Parser<'a> {
926926
let (args, args_span) = self.parse_precise_capturing_args()?;
927927
GenericBound::Use(args, use_span.to(args_span))
928928
} else {
929-
self.parse_generic_ty_bound(lo, has_parens, &leading_token)?
929+
self.parse_generic_ty_bound(lo, parens, &leading_token)?
930930
};
931931

932932
Ok(bound)
@@ -936,10 +936,14 @@ impl<'a> Parser<'a> {
936936
/// ```ebnf
937937
/// LT_BOUND = LIFETIME
938938
/// ```
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> {
940944
let lt = self.expect_lifetime();
941945
let bound = GenericBound::Outlives(lt);
942-
if has_parens {
946+
if let ast::Parens::Yes = parens {
943947
// FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
944948
// possibly introducing `GenericBound::Paren(P<GenericBound>)`?
945949
self.recover_paren_lifetime(lo)?;
@@ -1095,7 +1099,7 @@ impl<'a> Parser<'a> {
10951099
fn parse_generic_ty_bound(
10961100
&mut self,
10971101
lo: Span,
1098-
has_parens: bool,
1102+
parens: ast::Parens,
10991103
leading_token: &Token,
11001104
) -> PResult<'a, GenericBound> {
11011105
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
@@ -1121,7 +1125,7 @@ impl<'a> Parser<'a> {
11211125
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
11221126
if self.token.is_lifetime() {
11231127
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);
11251129
}
11261130

11271131
if let (more_lifetime_defs, Some(binder_span)) = self.parse_late_bound_lifetime_defs()? {
@@ -1188,7 +1192,7 @@ impl<'a> Parser<'a> {
11881192
self.recover_fn_trait_with_lifetime_params(&mut path, &mut lifetime_defs)?;
11891193
}
11901194

1191-
if has_parens {
1195+
if let ast::Parens::Yes = parens {
11921196
// Someone has written something like `&dyn (Trait + Other)`. The correct code
11931197
// would be `&(dyn Trait + Other)`
11941198
if self.token.is_like_plus() && leading_token.is_keyword(kw::Dyn) {
@@ -1207,13 +1211,12 @@ impl<'a> Parser<'a> {
12071211
}
12081212
}
12091213

1210-
let grouping = if has_parens { ast::Parens::Yes } else { ast::Parens::No };
12111214
let poly_trait = PolyTraitRef::new(
12121215
lifetime_defs,
12131216
path,
12141217
modifiers,
12151218
lo.to(self.prev_token.span),
1216-
grouping,
1219+
parens,
12171220
);
12181221
Ok(GenericBound::Trait(poly_trait))
12191222
}

0 commit comments

Comments
 (0)