From 3f62ab8f510fdac1eeab515c515c437d6dd141e6 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sun, 24 Mar 2019 19:45:11 +0200 Subject: Add WherePred to allow predicate access in WhereClause This also unifies parsing of WHERE_PRED bounds, now Lifetime bounds will also be parsed using TYPE_BOUND_LIST --- crates/ra_syntax/src/ast/generated.rs | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast/generated.rs') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9ea423b40..c51b4caa4 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -4810,7 +4810,48 @@ impl ToOwned for WhereClause { } -impl WhereClause {} +impl WhereClause { + pub fn predicates(&self) -> impl Iterator { + super::children(self) + } +} + +// WherePred +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct WherePred { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for WherePred { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for WherePred { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + WHERE_PRED => Some(WherePred::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for WherePred { + type Owned = TreeArc; + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl ast::TypeBoundsOwner for WherePred {} +impl WherePred { + pub fn type_ref(&self) -> Option<&TypeRef> { + super::child_opt(self) + } + + pub fn lifetime(&self) -> Option<&Lifetime> { + super::child_opt(self) + } +} // WhileExpr #[derive(Debug, PartialEq, Eq, Hash)] -- cgit v1.2.3