Remove make::match_arm_with_guard

This commit is contained in:
Lukas Wirth 2021-07-02 01:44:54 +02:00
parent 8967856d78
commit 071ac48b6c
7 changed files with 34 additions and 17 deletions

View file

@ -228,7 +228,7 @@ fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElemen
#[test]
fn test_increase_indent() {
let arm_list = {
let arm = make::match_arm(iter::once(make::wildcard_pat().into()), make::expr_unit());
let arm = make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit());
make::match_arm_list(vec![arm.clone(), arm])
};
assert_eq!(

View file

@ -421,9 +421,16 @@ pub fn path_pat(path: ast::Path) -> ast::Pat {
}
}
pub fn match_arm(pats: impl IntoIterator<Item = ast::Pat>, expr: ast::Expr) -> ast::MatchArm {
pub fn match_arm(
pats: impl IntoIterator<Item = ast::Pat>,
guard: Option<ast::Expr>,
expr: ast::Expr,
) -> ast::MatchArm {
let pats_str = pats.into_iter().join(" | ");
return from_text(&format!("{} => {}", pats_str, expr));
return match guard {
Some(guard) => from_text(&format!("{} if {} => {}", pats_str, guard, expr)),
None => from_text(&format!("{} => {}", pats_str, expr)),
};
fn from_text(text: &str) -> ast::MatchArm {
ast_from_text(&format!("fn f() {{ match () {{{}}} }}", text))