diff --git a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs index 1c403eafe3..2b68b2dc03 100644 --- a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs @@ -256,6 +256,7 @@ fn pick_pattern_and_expr_order( ) -> Option<(ast::Pat, ast::Expr, ast::Expr)> { let res = match (pat, pat2) { (ast::Pat::WildcardPat(_), _) => return None, + (pat, ast::Pat::WildcardPat(_)) => (pat, expr, expr2), (pat, _) if is_empty_expr(&expr2) => (pat, expr, expr2), (_, pat) if is_empty_expr(&expr) => (pat, expr2, expr), (pat, pat2) => match (binds_name(sema, &pat), binds_name(sema, &pat2)) { @@ -971,4 +972,28 @@ impl VariantData { } "#, ) } + + #[test] + fn test_replace_match_with_if_let_forces_else() { + check_assist( + replace_match_with_if_let, + r#" +fn main() { + match$0 0 { + 0 => (), + _ => code(), + } +} +"#, + r#" +fn main() { + if let 0 = 0 { + () + } else { + code() + } +} +"#, + ) + } }