aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast.rs2
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs29
2 files changed, 30 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
16pub use self::{ 16pub 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..e0ea3e5ab 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -382,7 +382,36 @@ impl ast::WherePred {
382 } 382 }
383} 383}
384 384
385#[derive(Clone, Debug, PartialEq, Eq, Hash)]
386pub enum TypeBoundKind {
387 /// Trait
388 PathType(ast::PathType),
389 /// for<'a> ...
390 ForType(ast::ForType),
391 /// 'a
392 Lifetime(ast::SyntaxToken),
393}
394
385impl ast::TypeBound { 395impl ast::TypeBound {
396 pub fn kind(&self) -> TypeBoundKind {
397 if let Some(path_type) = children(self).next() {
398 TypeBoundKind::PathType(path_type)
399 } else if let Some(for_type) = children(self).next() {
400 TypeBoundKind::ForType(for_type)
401 } else if let Some(lifetime) = self.lifetime() {
402 TypeBoundKind::Lifetime(lifetime)
403 } else {
404 unreachable!()
405 }
406 }
407
408 fn lifetime(&self) -> Option<SyntaxToken> {
409 self.syntax()
410 .children_with_tokens()
411 .filter_map(|it| it.into_token())
412 .find(|it| it.kind() == LIFETIME)
413 }
414
386 pub fn question_mark_token(&self) -> Option<SyntaxToken> { 415 pub fn question_mark_token(&self) -> Option<SyntaxToken> {
387 self.syntax() 416 self.syntax()
388 .children_with_tokens() 417 .children_with_tokens()