mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
feat: array match
This commit is contained in:
parent
3a72713365
commit
8fa69f9f7d
3 changed files with 157 additions and 11 deletions
|
@ -520,6 +520,15 @@ pub fn literal_pat(lit: &str) -> ast::LiteralPat {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn slice_pat(pats: impl IntoIterator<Item = ast::Pat>) -> ast::SlicePat {
|
||||
let pats_str = pats.into_iter().join(", ");
|
||||
return from_text(&format!("[{pats_str}]"));
|
||||
|
||||
fn from_text(text: &str) -> ast::SlicePat {
|
||||
ast_from_text(&format!("fn f() {{ match () {{{text} => ()}} }}"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a tuple of patterns from an iterator of patterns.
|
||||
///
|
||||
/// Invariant: `pats` must be length > 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue