mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
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:
parent
08e5d394df
commit
16a7d8cc85
8 changed files with 366 additions and 42 deletions
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue