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 false positives for variable named val #7588

Closed
romand opened this issue Aug 19, 2021 · 0 comments · Fixed by #7338
Closed

shadow_unrelated false positives for variable named val #7588

romand opened this issue Aug 19, 2021 · 0 comments · Fixed by #7338
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@romand
Copy link

romand commented Aug 19, 2021

When I name a variable val, next fn call with ? produces shadow_unrelated warning.
If I rename the variable, the warning disappears. Both on stable and nightly.
Reproducible with cargo clippy on this repo: https://github.com/romand/shadowed_val

I tried this code:

const fn bar() -> Result<(), Error> {
    Ok(())
}

pub fn foo() -> Result<(), Error> {
    let val = 1;
    bar()?;
    println!("{}", val);
    Ok(())
}

I expected to see this happen: no warnings

Instead, this happened:

    Checking shadowed_val v0.1.0 (/home/romand/shadowed_val)
error: `bar()?` is being shadowed
  --> src/lib.rs:14:5
   |
14 |     bar()?;
   |     ^^^^^^
   |
   = note: `-D clippy::shadow-unrelated` implied by `-D warnings`
note: initialization happens here
  --> src/lib.rs:14:5
   |
14 |     bar()?;
   |     ^^^^^^
note: previous binding is here
  --> src/lib.rs:13:9
   |
13 |     let val = 1;
   |         ^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated

error: aborting due to previous error

error: could not compile `shadowed_val`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: `bar()?` is being shadowed
  --> src/lib.rs:14:5
   |
14 |     bar()?;
   |     ^^^^^^
   |
   = note: `-D clippy::shadow-unrelated` implied by `-D warnings`
note: initialization happens here
  --> src/lib.rs:14:5
   |
14 |     bar()?;
   |     ^^^^^^
note: previous binding is here
  --> src/lib.rs:13:9
   |
13 |     let val = 1;
   |         ^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated

error: aborting due to previous error

error: build failed

cargo-clippy exited abnormally with code 101 at Thu Aug 19 13:58:18

Meta

  • cargo clippy -V: clippy 0.1.53 (53cb7b0 2021-06-17)
  • rustc -Vv:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1
@romand romand added the C-bug Category: Clippy is not doing the correct thing label Aug 19, 2021
@camsteffen camsteffen self-assigned this Aug 23, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants