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
This commit is contained in:
Ville Penttinen 2019-03-24 19:45:11 +02:00
parent 4666138c91
commit 3f62ab8f51
5 changed files with 132 additions and 8 deletions

View file

@ -4810,7 +4810,48 @@ impl ToOwned for WhereClause {
}
impl WhereClause {}
impl WhereClause {
pub fn predicates(&self) -> impl Iterator<Item = &WherePred> {
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<RaTypes>;
}
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<WherePred>;
fn to_owned(&self) -> TreeArc<WherePred> { 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)]