diff options
| author | bors <bors@rust-lang.org> | 2016-11-28 15:15:17 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-28 15:15:17 -0600 |
| commit | 1c448574bc668b0de70ed75223bf8798d17bf058 (patch) | |
| tree | 626a2bd26b17e8151a0f3537f6fe6107d54b3ee1 /src/libsyntax/parse/parser.rs | |
| parent | 39c267a8d5ab141faaf5d4b33a20cac62cdc4507 (diff) | |
| parent | 7d15250b0e5180137f5055b2e4333d5aac6579fe (diff) | |
| download | rust-1c448574bc668b0de70ed75223bf8798d17bf058.tar.gz rust-1c448574bc668b0de70ed75223bf8798d17bf058.zip | |
Auto merge of #37791 - petrochenkov:where, r=nikomatsakis
Support `?Sized` in where clauses Implemented as described in https://github.com/rust-lang/rust/issues/20503#issuecomment-258677026 - `?Trait` bounds are moved on type parameter definitions when possible, reported as errors otherwise. (It'd be nice to unify bounds and where clauses in HIR, but this is mostly blocked by rustdoc now - it needs to render bounds in pleasant way and the best way to do it so far is to mirror what was written in source code.) Fixes https://github.com/rust-lang/rust/issues/20503 r? @nikomatsakis
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -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()?; |
