Skip to content

Commit fbffe73

Browse files
committed
fix: Fix match to if let assist for wildcard pats
1 parent 62fede2 commit fbffe73

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

crates/ide-assists/src/handlers/replace_if_let_with_match.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ fn pick_pattern_and_expr_order(
256256
) -> Option<(ast::Pat, ast::Expr, ast::Expr)> {
257257
let res = match (pat, pat2) {
258258
(ast::Pat::WildcardPat(_), _) => return None,
259+
(pat, ast::Pat::WildcardPat(_)) => (pat, expr, expr2),
259260
(pat, _) if is_empty_expr(&expr2) => (pat, expr, expr2),
260261
(_, pat) if is_empty_expr(&expr) => (pat, expr2, expr),
261262
(pat, pat2) => match (binds_name(sema, &pat), binds_name(sema, &pat2)) {
@@ -971,4 +972,28 @@ impl VariantData {
971972
} "#,
972973
)
973974
}
975+
976+
#[test]
977+
fn test_replace_match_with_if_let_forces_else() {
978+
check_assist(
979+
replace_match_with_if_let,
980+
r#"
981+
fn main() {
982+
match$0 0 {
983+
0 => (),
984+
_ => code(),
985+
}
986+
}
987+
"#,
988+
r#"
989+
fn main() {
990+
if let 0 = 0 {
991+
()
992+
} else {
993+
code()
994+
}
995+
}
996+
"#,
997+
)
998+
}
974999
}

0 commit comments

Comments
 (0)