Put leading | in patterns under OrPat

Previously it was one level above, and that caused problems with macros that expand to it, because macros expect to get only one top-level node.
This commit is contained in:
Chayim Refael Friedman 2024-10-27 05:08:49 +02:00
parent 6a67a4d3cd
commit e12a001b55
11 changed files with 87 additions and 31 deletions

View file

@ -1283,6 +1283,8 @@ pub struct OrPat {
impl OrPat {
#[inline]
pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
#[inline]
pub fn pipe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![|]) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

View file

@ -1140,3 +1140,13 @@ impl From<ast::AssocItem> for ast::AnyHasAttrs {
Self::new(node)
}
}
impl ast::OrPat {
pub fn leading_pipe(&self) -> Option<SyntaxToken> {
self.syntax
.children_with_tokens()
.find(|it| !it.kind().is_trivia())
.and_then(NodeOrToken::into_token)
.filter(|it| it.kind() == T![|])
}
}