From 78a19d9b88d499449e53ebfb89301b36810e3c34 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Fri, 27 Apr 2018 17:32:54 +0900 Subject: [PATCH] Include parens to type parameter --- src/libsyntax/parse/parser.rs | 9 +++++++-- src/test/ui/maybe-bounds.stderr | 12 ++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 53d0b5529ef..5428842c7f7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4875,6 +4875,7 @@ fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, TyPa 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() { @@ -4883,10 +4884,15 @@ fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, TyPa "`?` may only modify trait bounds, not lifetime bounds"); } bounds.push(RegionTyParamBound(self.expect_lifetime())); + if has_parens { + self.expect(&token::CloseDelim(token::Paren))?; + } } 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 @@ -4896,7 +4902,6 @@ fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, TyPa 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"); diff --git a/src/test/ui/maybe-bounds.stderr b/src/test/ui/maybe-bounds.stderr index 72f052b75e3..763fec77be3 100644 --- a/src/test/ui/maybe-bounds.stderr +++ b/src/test/ui/maybe-bounds.stderr @@ -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 - | ^^^^^ + | ^^^^^^ | = 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 - | ^^^^^ + | ^^^^^^ 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 - | ^^^^^ + | ^^^^^^ error: aborting due to 3 previous errors