diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/extensions.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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)] | ||
386 | pub enum TypeBoundKind { | ||
387 | /// Trait | ||
388 | PathType(ast::PathType), | ||
389 | /// for<'a> ... | ||
390 | ForType(ast::ForType), | ||
391 | /// 'a | ||
392 | Lifetime(ast::SyntaxToken), | ||
393 | } | ||
394 | |||
385 | impl ast::TypeBound { | 395 | impl 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() |