Skip to content

Commit 3662bd8

Browse files
committed
Auto merge of #11623 - koka831:fix/11619, r=llogiq
Fix ice in `redundant_locals` Fixes #11619 Rebinding over macro like the code below, idents will be different (`x#4` and `x#0` in that case). ```rust fn reassign_in_macro() { let x = 10; macro_rules! mac { ($i:ident) => { let mut x = x; } } mac!(y); } ``` It causes unwrapping `None`. https://github.com/rust-lang/rust-clippy/blob/9554e477c29e6ddca9e5cdce71524341ef9d48e8/clippy_lints/src/redundant_locals.rs#L88-L98 changelog: ICE: [`redundant_locals`]: No longer lints rebinding over macro
2 parents b105fb4 + 68d2082 commit 3662bd8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

clippy_lints/src/redundant_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
6262
if let Res::Local(binding_id) = cx.qpath_res(&qpath, expr.hir_id);
6363
if let Node::Pat(binding_pat) = cx.tcx.hir().get(binding_id);
6464
// the previous binding has the same mutability
65-
if find_binding(binding_pat, ident).unwrap().1 == mutability;
65+
if find_binding(binding_pat, ident).is_some_and(|bind| bind.1 == mutability);
6666
// the local does not change the effect of assignments to the binding. see #11290
6767
if !affects_assignments(cx, mutability, binding_id, local.hir_id);
6868
// the local does not affect the code's drop behavior

tests/ui/redundant_locals.rs

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ fn macros() {
117117
let x = 1;
118118
let x = x;
119119
}
120+
121+
let x = 10;
122+
macro_rules! rebind_outer_macro {
123+
($x:ident) => {
124+
let x = x;
125+
};
126+
}
127+
rebind_outer_macro!(y);
120128
}
121129

122130
struct WithDrop(usize);

tests/ui/redundant_locals.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ LL | let x = 1;
157157
| ^
158158

159159
error: redundant redefinition of a binding `a`
160-
--> $DIR/redundant_locals.rs:144:5
160+
--> $DIR/redundant_locals.rs:152:5
161161
|
162162
LL | let a = a;
163163
| ^^^^^^^^^^
164164
|
165165
help: `a` is initially defined here
166-
--> $DIR/redundant_locals.rs:142:9
166+
--> $DIR/redundant_locals.rs:150:9
167167
|
168168
LL | let a = WithoutDrop(1);
169169
| ^

0 commit comments

Comments
 (0)