Repository: rust-analyzer/rust-analyzer
Pull request #11180 (2022-01-03 14:22:17)

minor: add missing test
This test kills the following mutant:

diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 9d2b1da9a..055d9a733 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -134,7 +134,7 @@ impl<'a> TtIter<'a> {
         self.inner = self.inner.as_slice()[res.len()..].iter();
         let res = match res.len() {
             1 => Some(res[0].cloned()),
-            0 => None,
+            // 0 => None,
             _ => Some(tt::TokenTree::Subtree(tt::Subtree {
                 delimiter: None,
                 token_trees: res.into_iter().map(|it| it.cloned()).collect(),

bors r+
🤖


Patch:
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 7790934792..47d1fbe144 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
@@ -207,23 +207,21 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext)
         "Replace match with if let",
         target,
         move |edit| {
-            fn make_block_expr(expr: ast::Expr) -> ast::BlockExpr {
-                // Blocks with modifiers (unsafe, async, etc.) are parsed as BlockExpr, but are
-                // formatted without enclosing braces. If we encounter such block exprs,
-                // wrap them in another BlockExpr.
-                match expr {
-                    ast::Expr::BlockExpr(block) if block.modifier().is_none() => block,
-                    expr => make::block_expr(iter::empty(), Some(expr)),
-                }
-            }
-
             let condition = make::condition(scrutinee, Some(if_let_pat));
-            let then_block = make_block_expr(then_expr.reset_indent());
+            let then_block = match then_expr.reset_indent() {
+                ast::Expr::BlockExpr(block) => block,
+                expr => make::block_expr(iter::empty(), Some(expr)),
+            };
             let else_expr = if is_empty_expr(&else_expr) { None } else { Some(else_expr) };
             let if_let_expr = make::expr_if(
                 condition,
                 then_block,
-                else_expr.map(make_block_expr).map(ast::ElseBranch::Block),
+                else_expr
+                    .map(|expr| match expr {
+                        ast::Expr::BlockExpr(block) => block,
+                        expr => (make::block_expr(iter::empty(), Some(expr))),
+                    })
+                    .map(ast::ElseBranch::Block),
             )
             .indent(IndentLevel::from_node(match_expr.syntax()));
 
@@ -919,30 +917,4 @@ fn foo() {
 "#,
         );
     }
-
-    #[test]
-    fn test_replace_match_with_if_let_keeps_unsafe_block() {
-        check_assist(
-            replace_match_with_if_let,
-            r#"
-impl VariantData {
-    pub fn is_struct(&self) -> bool {
-        $0match *self {
-            VariantData::Struct(..) => true,
-            _ => unsafe { unreachable_unchecked() },
-        }
-    }
-}           "#,
-            r#"
-impl VariantData {
-    pub fn is_struct(&self) -> bool {
-        if let VariantData::Struct(..) = *self {
-            true
-        } else {
-            unsafe { unreachable_unchecked() }
-        }
-    }
-}           "#,
-        )
-    }
 }


Test patch:
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
index 517dfb15b6..bc162d0fa2 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
@@ -122,3 +122,17 @@ stringify!(.. .. ..|);
 "#]],
     );
 }
+
+#[test]
+fn trailing_vis() {
+    check(
+        r#"
+macro_rules! m { ($($i:ident)? $vis:vis) => () }
+m!(x pub);
+"#,
+        expect![[r#"
+macro_rules! m { ($($i:ident)? $vis:vis) => () }
+
+"#]],
+    )
+}