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

shadow_unrelated does not register a variable being shadowed #7620

Closed
nemqe opened this issue Sep 1, 2021 · 0 comments · Fixed by #7338
Closed

shadow_unrelated does not register a variable being shadowed #7620

nemqe opened this issue Sep 1, 2021 · 0 comments · Fixed by #7338
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@nemqe
Copy link

nemqe commented Sep 1, 2021

I accidentally shadowed a variable without knowing and the linter did not warn me about that. Not a huge deal but just wanted to report the issue.

Lint name:
shadow_unrelated

I tried this code:

let s = "&str";
println!("{}", s);

let s = String::from("String");
println!("{}", s);

let x = 1;
println!("{}", x);

let x = "2".parse::<i32>().unwrap();
println!("{}", x);

I expected to see this happen: Warning shown about variables s and x being shadowed when running cargo clippy -- -W clippy::shadow_reuse -W clippy::shadow_same -W clippy::shadow_unrelated.

Instead, this happened: No warning for variable s was shown.

Meta

Rust version (rustc -Vv):

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1
@nemqe nemqe added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Sep 1, 2021
bors added a commit that referenced this issue Sep 30, 2021
Re-write shadow lints

changelog: Move shadow_unrelated to restriction
changelog: The shadow lints find a lot more shadows and are not limited to certain patterns

Drastically simplifies the implementation. Catches a lot more cases.

I removed the "initialization happens here" note. It is not helpful IMO.

Closes #318
Fixes #2890
Fixes #6563
Fixes #7588
Fixes #7620
@bors bors closed this as completed in f8303ad Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant