1
Fork 0

syntax: add anonymized type syntax, i.e. impl TraitA+TraitB.

This commit is contained in:
Eduard Burtescu 2016-08-01 04:25:32 +03:00
parent c976e073fd
commit f0baec691f
13 changed files with 68 additions and 4 deletions

View file

@ -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())?