Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ice in redundant_locals #11623

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/redundant_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/redundant_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/redundant_locals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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);
| ^
Expand Down