-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
shadow_unrelated is using idents from RHS of assignment #6141
Comments
Also address new clippy lints and updates. This commit disables some lints due to rust-lang/rust-clippy#6137 and rust-lang/rust-clippy#6141.
Here's a minimal example of what I think might be the same thing, using the recently landed #[warn(clippy::shadow_unrelated)]
fn multiple_assignment_produces_false_positive() {
let mut n = 0;
let mut b = false;
loop {
(n, b) = f(n, b); // warning: `b` is being shadowed - doesn't warn about `n`, though
}
}
fn f(a: usize, b: bool) -> (usize, bool) {
(a + 1, !b)
} With a single assignment, there's no warning: #[warn(clippy::shadow_unrelated)]
fn single_assignment_produces_true_negative() {
let mut n = 0;
loop {
n = f_prime(n); // no warning about `n` being shadowed
}
}
fn f_prime(a: usize) -> usize {
a + 1
} |
Would this be the same issue as #[warn(clippy::shadow_unrelated)]
pub fn example(v: &mut u32) -> u32 {
let s;
(*v, s) = (0, 0);
// ^ `s` shadows a previous, unrelated binding
s
} Or should I open a new issue? Key difference is the second var is an initialization not a mutation. |
Clippy doesn't see a difference between delayed init and mutation, so I don't think a new issue is necessary. |
Clippy outputs these warnings:
For this code:
and
I expected to see this happen: No errors, as in Rust 1.46.0
Meta
cargo clippy -V
: clippy 0.0.212 (18bf6b4f0 2020-10-07)rustc -Vv
:The text was updated successfully, but these errors were encountered: