diff options
author | Florian Diebold <[email protected]> | 2019-08-13 22:09:08 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-08-22 18:33:00 +0100 |
commit | 16a7d8cc850002b427fdc8d21ccde81caaed7902 (patch) | |
tree | 7f3c43cf9e83d479edc7f9b4849dae5fbd0f356d /crates/ra_syntax | |
parent | 08e5d394dfbca28b15ed5dc772d55d48f87c3f54 (diff) |
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
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 6f0489617..afdfca66e 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
15 | 15 | ||
16 | pub use self::{ | 16 | pub use self::{ |
17 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp}, | 17 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp}, |
18 | extensions::{FieldKind, PathSegmentKind, SelfParamKind, StructKind}, | 18 | extensions::{FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind}, |
19 | generated::*, | 19 | generated::*, |
20 | tokens::*, | 20 | tokens::*, |
21 | traits::*, | 21 | traits::*, |
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 { | |||
399 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) | 399 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) |
400 | } | 400 | } |
401 | } | 401 | } |
402 | |||
403 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
404 | pub enum TypeBoundKind { | ||
405 | /// Trait | ||
406 | PathType(ast::PathType), | ||
407 | /// for<'a> ... | ||
408 | ForType(ast::ForType), | ||
409 | /// 'a | ||
410 | Lifetime(ast::SyntaxToken), | ||
411 | } | ||
412 | |||
413 | impl ast::TypeBound { | ||
414 | pub fn kind(&self) -> Option<TypeBoundKind> { | ||
415 | let child = self.syntax.first_child_or_token()?; | ||
416 | match child.kind() { | ||
417 | PATH_TYPE => Some(TypeBoundKind::PathType( | ||
418 | ast::PathType::cast(child.into_node().unwrap()).unwrap(), | ||
419 | )), | ||
420 | FOR_TYPE => Some(TypeBoundKind::ForType( | ||
421 | ast::ForType::cast(child.into_node().unwrap()).unwrap(), | ||
422 | )), | ||
423 | LIFETIME => Some(TypeBoundKind::Lifetime(child.into_token().unwrap())), | ||
424 | _ => unreachable!(), | ||
425 | } | ||
426 | } | ||
427 | } | ||