Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include parens to type parameter #50205

Merged
merged 3 commits into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4875,6 +4875,7 @@ impl<'a> Parser<'a> {
self.check_keyword(keywords::For) ||
self.check(&token::OpenDelim(token::Paren));
if is_bound_start {
let lo = self.span;
let has_parens = self.eat(&token::OpenDelim(token::Paren));
let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None };
if self.token.is_lifetime() {
Expand All @@ -4883,10 +4884,17 @@ impl<'a> Parser<'a> {
"`?` may only modify trait bounds, not lifetime bounds");
}
bounds.push(RegionTyParamBound(self.expect_lifetime()));
if has_parens {
self.expect(&token::CloseDelim(token::Paren))?;
self.span_err(self.prev_span,
"parenthesized lifetime bounds are not supported");
}
} else {
let lo = self.span;
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
let path = self.parse_path(PathStyle::Type)?;
if has_parens {
self.expect(&token::CloseDelim(token::Paren))?;
}
let poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
let modifier = if question.is_some() {
TraitBoundModifier::Maybe
Expand All @@ -4895,13 +4903,6 @@ impl<'a> Parser<'a> {
};
bounds.push(TraitTyParamBound(poly_trait, modifier));
}
if has_parens {
self.expect(&token::CloseDelim(token::Paren))?;
if let Some(&RegionTyParamBound(..)) = bounds.last() {
self.span_err(self.prev_span,
"parenthesized lifetime bounds are not supported");
}
}
} else {
break
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/maybe-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

fn main() {}
16 changes: 8 additions & 8 deletions src/test/ui/maybe-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
error: `?Trait` is not permitted in supertraits
--> $DIR/maybe-bounds.rs:11:12
--> $DIR/maybe-bounds.rs:11:11
|
LL | trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
| ^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@topecongiro

Though I am not sure how I should test the new code

You can put any of ?Sizeds in this test into parentheses, that would be enough.

| ^^^^^^
|
= note: traits are `?Sized` by default

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

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

error: aborting due to 3 previous errors