From 16a7d8cc850002b427fdc8d21ccde81caaed7902 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 13 Aug 2019 23:09:08 +0200 Subject: 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 --- crates/ra_syntax/src/ast/extensions.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index efe261fc2..8de979ca2 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -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 { + 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!(), + } + } +} -- cgit v1.2.3