about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkoka <koka.code@gmail.com>2023-10-06 18:22:32 +0900
committerkoka <koka.code@gmail.com>2023-10-07 01:28:06 +0900
commit68d2082d69d61af56d0b9d73035b274ea0e2e8de (patch)
tree1122b527978f00670657f50ba5f28d89a5fb06c5
parentb105fb4c39bc1a010807a6c076193cef8d93c109 (diff)
downloadrust-68d2082d69d61af56d0b9d73035b274ea0e2e8de.tar.gz
rust-68d2082d69d61af56d0b9d73035b274ea0e2e8de.zip
Fix ice
-rw-r--r--clippy_lints/src/redundant_locals.rs2
-rw-r--r--tests/ui/redundant_locals.rs8
-rw-r--r--tests/ui/redundant_locals.stderr4
3 files changed, 11 insertions, 3 deletions
diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs
index 197742b5dd4..a1a0e8f3520 100644
--- a/clippy_lints/src/redundant_locals.rs
+++ b/clippy_lints/src/redundant_locals.rs
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
             if let Res::Local(binding_id) = cx.qpath_res(&qpath, expr.hir_id);
             if let Node::Pat(binding_pat) = cx.tcx.hir().get(binding_id);
             // the previous binding has the same mutability
-            if find_binding(binding_pat, ident).unwrap().1 == mutability;
+            if find_binding(binding_pat, ident).is_some_and(|bind| bind.1 == mutability);
             // the local does not change the effect of assignments to the binding. see #11290
             if !affects_assignments(cx, mutability, binding_id, local.hir_id);
             // the local does not affect the code's drop behavior
diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs
index e81db300f15..182d067a5e9 100644
--- a/tests/ui/redundant_locals.rs
+++ b/tests/ui/redundant_locals.rs
@@ -117,6 +117,14 @@ fn macros() {
         let x = 1;
         let x = x;
     }
+
+    let x = 10;
+    macro_rules! rebind_outer_macro {
+        ($x:ident) => {
+            let x = x;
+        };
+    }
+    rebind_outer_macro!(y);
 }
 
 struct WithDrop(usize);
diff --git a/tests/ui/redundant_locals.stderr b/tests/ui/redundant_locals.stderr
index d794a87fe7d..30ab4aa2ea9 100644
--- a/tests/ui/redundant_locals.stderr
+++ b/tests/ui/redundant_locals.stderr
@@ -157,13 +157,13 @@ LL |     let x = 1;
    |         ^
 
 error: redundant redefinition of a binding `a`
-  --> $DIR/redundant_locals.rs:144:5
+  --> $DIR/redundant_locals.rs:152:5
    |
 LL |     let a = a;
    |     ^^^^^^^^^^
    |
 help: `a` is initially defined here
-  --> $DIR/redundant_locals.rs:142:9
+  --> $DIR/redundant_locals.rs:150:9
    |
 LL |     let a = WithoutDrop(1);
    |         ^