diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-10-22 03:33:36 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-11-25 00:43:00 +0300 |
| commit | 7d15250b0e5180137f5055b2e4333d5aac6579fe (patch) | |
| tree | 4e55f5d402a1ad0a799927d9c69a8b7fc933f63a /src/libsyntax/parse | |
| parent | a31ad75bdedab55ca290332edda9acbd2d5a0157 (diff) | |
| download | rust-7d15250b0e5180137f5055b2e4333d5aac6579fe.tar.gz rust-7d15250b0e5180137f5055b2e4333d5aac6579fe.zip | |
Support `?Sized` in where clauses
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 49226be4147..bdd1606805f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -88,13 +88,6 @@ pub enum PathStyle { Expr, } -/// How to parse a bound, whether to allow bound modifiers such as `?`. -#[derive(Copy, Clone, PartialEq)] -pub enum BoundParsingMode { - Bare, - Modified, -} - #[derive(Clone, Copy, PartialEq)] pub enum SemiColonMode { Break, @@ -1041,7 +1034,7 @@ impl<'a> Parser<'a> { trait_ref: trait_ref, span: mk_sp(lo, hi)}; let other_bounds = if self.eat(&token::BinOp(token::Plus)) { - self.parse_ty_param_bounds(BoundParsingMode::Bare)? + self.parse_ty_param_bounds()? } else { P::new() }; @@ -1059,7 +1052,7 @@ impl<'a> Parser<'a> { The `impl` has already been consumed. */ - let bounds = self.parse_ty_param_bounds(BoundParsingMode::Modified)?; + let bounds = self.parse_ty_param_bounds()?; if !bounds.iter().any(|b| if let TraitTyParamBound(..) = *b { true } else { false }) { self.span_err(self.prev_span, "at least one trait must be specified"); @@ -1271,7 +1264,7 @@ impl<'a> Parser<'a> { return Ok(lhs); } - let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; + let bounds = self.parse_ty_param_bounds()?; // In type grammar, `+` is treated like a binary operator, // and hence both L and R side are required. @@ -4148,14 +4141,12 @@ impl<'a> Parser<'a> { // Parses a sequence of bounds if a `:` is found, // otherwise returns empty list. - fn parse_colon_then_ty_param_bounds(&mut self, - mode: BoundParsingMode) - -> PResult<'a, TyParamBounds> + fn parse_colon_then_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds> { if !self.eat(&token::Colon) { Ok(P::new()) } else { - self.parse_ty_param_bounds(mode) + self.parse_ty_param_bounds() } } @@ -4163,9 +4154,7 @@ impl<'a> Parser<'a> { // where boundseq = ( polybound + boundseq ) | polybound // and polybound = ( 'for' '<' 'region '>' )? bound // and bound = 'region | trait_ref - fn parse_ty_param_bounds(&mut self, - mode: BoundParsingMode) - -> PResult<'a, TyParamBounds> + fn parse_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds> { let mut result = vec![]; loop { @@ -4187,13 +4176,7 @@ impl<'a> Parser<'a> { token::ModSep | token::Ident(..) => { let poly_trait_ref = self.parse_poly_trait_ref()?; let modifier = if ate_question { - if mode == BoundParsingMode::Modified { - TraitBoundModifier::Maybe - } else { - self.span_err(question_span, - "unexpected `?`"); - TraitBoundModifier::None - } + TraitBoundModifier::Maybe } else { TraitBoundModifier::None }; @@ -4215,7 +4198,7 @@ impl<'a> Parser<'a> { let span = self.span; let ident = self.parse_ident()?; - let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)?; + let bounds = self.parse_colon_then_ty_param_bounds()?; let default = if self.check(&token::Eq) { self.bump(); @@ -4439,7 +4422,7 @@ impl<'a> Parser<'a> { let bounded_ty = self.parse_ty()?; if self.eat(&token::Colon) { - let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; + let bounds = self.parse_ty_param_bounds()?; let hi = self.prev_span.hi; let span = mk_sp(lo, hi); @@ -4901,7 +4884,7 @@ impl<'a> Parser<'a> { let mut tps = self.parse_generics()?; // Parse supertrait bounds. - let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)?; + let bounds = self.parse_colon_then_ty_param_bounds()?; tps.where_clause = self.parse_where_clause()?; |
