Add impl Trait and dyn Trait types

- refactor bounds handling in the AST a bit
 - add HIR for bounds
 - add `Ty::Dyn` and `Ty::Opaque` variants and lower `dyn Trait` / `impl Trait`
   syntax to them
This commit is contained in:
Florian Diebold 2019-08-13 23:09:08 +02:00
parent 08e5d394df
commit 16a7d8cc85
8 changed files with 366 additions and 42 deletions

View file

@ -399,3 +399,29 @@ impl ast::TraitDef {
self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum TypeBoundKind {
/// Trait
PathType(ast::PathType),
/// for<'a> ...
ForType(ast::ForType),
/// 'a
Lifetime(ast::SyntaxToken),
}
impl ast::TypeBound {
pub fn kind(&self) -> Option<TypeBoundKind> {
let child = self.syntax.first_child_or_token()?;
match child.kind() {
PATH_TYPE => Some(TypeBoundKind::PathType(
ast::PathType::cast(child.into_node().unwrap()).unwrap(),
)),
FOR_TYPE => Some(TypeBoundKind::ForType(
ast::ForType::cast(child.into_node().unwrap()).unwrap(),
)),
LIFETIME => Some(TypeBoundKind::Lifetime(child.into_token().unwrap())),
_ => unreachable!(),
}
}
}