mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Implement slice pattern AST > HIR lowering
This commit is contained in:
parent
3e1d97790b
commit
a3b104aa6d
8 changed files with 64 additions and 13 deletions
|
@ -1,6 +1,8 @@
|
|||
//! Various extension methods to ast Nodes, which are hard to code-generate.
|
||||
//! Extensions for various expressions live in a sibling `expr_extensions` module.
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode},
|
||||
SmolStr, SyntaxElement,
|
||||
|
@ -293,6 +295,40 @@ impl ast::BindPat {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SlicePatComponents {
|
||||
pub prefix: Vec<ast::Pat>,
|
||||
pub slice: Option<ast::Pat>,
|
||||
pub suffix: Vec<ast::Pat>,
|
||||
}
|
||||
|
||||
impl ast::SlicePat {
|
||||
pub fn components(&self) -> SlicePatComponents {
|
||||
let mut args = self.args().peekable();
|
||||
let prefix = args
|
||||
.peeking_take_while(|p| match p {
|
||||
ast::Pat::DotDotPat(_) => false,
|
||||
ast::Pat::BindPat(bp) => match bp.pat() {
|
||||
Some(ast::Pat::DotDotPat(_)) => false,
|
||||
_ => true,
|
||||
},
|
||||
ast::Pat::RefPat(rp) => match rp.pat() {
|
||||
Some(ast::Pat::DotDotPat(_)) => false,
|
||||
Some(ast::Pat::BindPat(bp)) => match bp.pat() {
|
||||
Some(ast::Pat::DotDotPat(_)) => false,
|
||||
_ => true,
|
||||
},
|
||||
_ => true,
|
||||
},
|
||||
_ => true,
|
||||
})
|
||||
.collect();
|
||||
let slice = args.next();
|
||||
let suffix = args.collect();
|
||||
|
||||
SlicePatComponents { prefix, slice, suffix }
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::PointerType {
|
||||
pub fn is_mut(&self) -> bool {
|
||||
self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue