about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-06-05 01:02:24 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-06-05 01:02:24 +0200
commitfbffe736121d1eba7eb3fc1bf4b115c3cca672cf (patch)
tree40f6cb2a13dbba2601ee919b2a124ce92edf969c
parent62fede212ac6c8f0cb8948ece79a237cfb18e095 (diff)
downloadrust-fbffe736121d1eba7eb3fc1bf4b115c3cca672cf.tar.gz
rust-fbffe736121d1eba7eb3fc1bf4b115c3cca672cf.zip
fix: Fix match to if let assist for wildcard pats
-rw-r--r--crates/ide-assists/src/handlers/replace_if_let_with_match.rs25
1 files changed, 25 insertions, 0 deletions
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 1c403eafe30..2b68b2dc03a 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()
+    }
+}
+"#,
+        )
+    }
 }