diff options
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c143e190c6f..1b32632a06f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1051,7 +1051,7 @@ impl<'a> Parser<'a> { pub fn parse_for_in_type(&mut self) -> PResult<'a, TyKind> { /* Parses whatever can come after a `for` keyword in a type. - The `for` has already been consumed. + The `for` hasn't been consumed. Deprecated: @@ -1091,6 +1091,23 @@ impl<'a> Parser<'a> { } } + pub fn parse_impl_trait_type(&mut self) -> PResult<'a, TyKind> { + /* + Parses whatever can come after a `impl` keyword in a type. + The `impl` has already been consumed. + */ + + let bounds = self.parse_ty_param_bounds(BoundParsingMode::Modified)?; + + if !bounds.iter().any(|b| if let TraitTyParamBound(..) = *b { true } else { false }) { + let last_span = self.last_span; + self.span_err(last_span, "at least one trait must be specified"); + } + + Ok(ast::TyKind::ImplTrait(bounds)) + } + + pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> { Ok(TyKind::Path(None, self.parse_path(PathStyle::Type)?)) } @@ -1406,6 +1423,8 @@ impl<'a> Parser<'a> { self.parse_borrowed_pointee()? } else if self.check_keyword(keywords::For) { self.parse_for_in_type()? + } else if self.eat_keyword(keywords::Impl) { + self.parse_impl_trait_type()? } else if self.token_is_bare_fn_keyword() { // BARE FUNCTION self.parse_ty_bare_fn(Vec::new())? |
