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 https://github.com/rust-lang-nursery/rustfmt/issues/2630).
This commit is contained in:
commit
a805a2a5eb
3 changed files with 19 additions and 18 deletions
|
@ -4746,6 +4746,7 @@ impl<'a> Parser<'a> {
|
||||||
self.check_keyword(keywords::For) ||
|
self.check_keyword(keywords::For) ||
|
||||||
self.check(&token::OpenDelim(token::Paren));
|
self.check(&token::OpenDelim(token::Paren));
|
||||||
if is_bound_start {
|
if is_bound_start {
|
||||||
|
let lo = self.span;
|
||||||
let has_parens = self.eat(&token::OpenDelim(token::Paren));
|
let has_parens = self.eat(&token::OpenDelim(token::Paren));
|
||||||
let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None };
|
let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None };
|
||||||
if self.token.is_lifetime() {
|
if self.token.is_lifetime() {
|
||||||
|
@ -4754,10 +4755,17 @@ impl<'a> Parser<'a> {
|
||||||
"`?` may only modify trait bounds, not lifetime bounds");
|
"`?` may only modify trait bounds, not lifetime bounds");
|
||||||
}
|
}
|
||||||
bounds.push(RegionTyParamBound(self.expect_lifetime()));
|
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 {
|
} else {
|
||||||
let lo = self.span;
|
|
||||||
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
|
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
|
||||||
let path = self.parse_path(PathStyle::Type)?;
|
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 poly_trait = PolyTraitRef::new(lifetime_defs, path, lo.to(self.prev_span));
|
||||||
let modifier = if question.is_some() {
|
let modifier = if question.is_some() {
|
||||||
TraitBoundModifier::Maybe
|
TraitBoundModifier::Maybe
|
||||||
|
@ -4766,13 +4774,6 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
bounds.push(TraitTyParamBound(poly_trait, modifier));
|
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 {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
|
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
|
||||||
|
|
||||||
type A1 = 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
|
type A2 = for<'a> Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
error: `?Trait` is not permitted in supertraits
|
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
|
LL | trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
|
||||||
| ^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= note: traits are `?Sized` by default
|
= note: traits are `?Sized` by default
|
||||||
|
|
||||||
error: `?Trait` is not permitted in trait object types
|
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
|
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
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue