Skip to content

Commit a805a2a

Browse files
committed
Auto merge of #50205 - topecongiro:include-parens-to-type-parameter, r=petrochenkov
Include parens to type parameter The motivation of this PR is to fix a bug in rustfmt (cc rust-lang/rustfmt#2630).
2 parents cabb679 + dc87d0d commit a805a2a

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/libsyntax/parse/parser.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -4746,6 +4746,7 @@ impl<'a> Parser<'a> {
47464746
self.check_keyword(keywords::For) ||
47474747
self.check(&token::OpenDelim(token::Paren));
47484748
if is_bound_start {
4749+
let lo = self.span;
47494750
let has_parens = self.eat(&token::OpenDelim(token::Paren));
47504751
let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None };
47514752
if self.token.is_lifetime() {
@@ -4754,10 +4755,17 @@ impl<'a> Parser<'a> {
47544755
"`?` may only modify trait bounds, not lifetime bounds");
47554756
}
47564757
bounds.push(RegionTyParamBound(self.expect_lifetime()));
4758+
if has_parens {
4759+
self.expect(&token::CloseDelim(token::Paren))?;
4760+
self.span_err(self.prev_span,
4761+
"parenthesized lifetime bounds are not supported");
4762+
}
47574763
} else {
4758-
let lo = self.span;
47594764
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
47604765
let path = self.parse_path(PathStyle::Type)?;
4766+
if has_parens {
4767+
self.expect(&token::CloseDelim(token::Paren))?;
4768+
}
47614769
let poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
47624770
let modifier = if question.is_some() {
47634771
TraitBoundModifier::Maybe
@@ -4766,13 +4774,6 @@ impl<'a> Parser<'a> {
47664774
};
47674775
bounds.push(TraitTyParamBound(poly_trait, modifier));
47684776
}
4769-
if has_parens {
4770-
self.expect(&token::CloseDelim(token::Paren))?;
4771-
if let Some(&RegionTyParamBound(..)) = bounds.last() {
4772-
self.span_err(self.prev_span,
4773-
"parenthesized lifetime bounds are not supported");
4774-
}
4775-
}
47764777
} else {
47774778
break
47784779
}

src/test/ui/maybe-bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
1212

13-
type A1 = Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types
14-
type A2 = for<'a> Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types
13+
type A1 = Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
14+
type A2 = for<'a> Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
1515

1616
fn main() {}

src/test/ui/maybe-bounds.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error: `?Trait` is not permitted in supertraits
2-
--> $DIR/maybe-bounds.rs:11:12
2+
--> $DIR/maybe-bounds.rs:11:11
33
|
44
LL | trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
5-
| ^^^^^
5+
| ^^^^^^
66
|
77
= note: traits are `?Sized` by default
88

99
error: `?Trait` is not permitted in trait object types
10-
--> $DIR/maybe-bounds.rs:13:17
10+
--> $DIR/maybe-bounds.rs:13:16
1111
|
12-
LL | type A1 = Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types
13-
| ^^^^^
12+
LL | type A1 = Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
13+
| ^^^^^^^^
1414

1515
error: `?Trait` is not permitted in trait object types
16-
--> $DIR/maybe-bounds.rs:14:25
16+
--> $DIR/maybe-bounds.rs:14:24
1717
|
18-
LL | type A2 = for<'a> Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types
19-
| ^^^^^
18+
LL | type A2 = for<'a> Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
19+
| ^^^^^^^^
2020

2121
error: aborting due to 3 previous errors
2222

0 commit comments

Comments
 (0)