Auto merge of #13978 - bvanjoi:array-match, r=Veykril

feat: array match

fixed https://github.com/rust-lang/rust-analyzer/issues/13970
This commit is contained in:
bors 2023-01-20 10:30:18 +00:00
commit d46d012c38
3 changed files with 157 additions and 11 deletions

View file

@ -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