I'm about to file an issue on this but I wanted to check to see if there is disagreement about it being a bug. This code:
#[deny(clippy::shadow_unrelated)]
{
let (mut x, mut y) = (1, 2);
(x, y) = (3, 4);
}
results in this error:
error: `y` shadows a previous, unrelated binding
--> src/main.rs:6:13
|
6 | (x, y) = (3, 4);
| ^
|
note: previous binding is here
--> src/main.rs:6:10
|
6 | (x, y) = (3, 4);
| ^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated
note: the lint level is defined here
--> src/main.rs:3:12
|
3 | #[deny(clippy::shadow_unrelated)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
Since this is just assigning mutable variables and there is no new let
, it should not be considered shadowing. Also it's strange that the error message says that y
is shadowing x
.
playground (run clippy in the tools menu)
kpreid
February 1, 2025, 3:45am
2
Yes, that doesn’t make any sense.
There's a pre-existing issue though.
opened 08:21PM - 02 Feb 23 UTC
C-bug
I-false-positive
### Summary
Clippy appears to incorrectly flag the second variable in a destruc… turing assignment as shadowing the first, even when the two variables are different.
I do not see this behavior with a destructuring let binding, even when they *do* shadow other variables.
### Lint Name
shadow_unrelated
### Reproducer
I tried this code:
```rust
#![warn(clippy::shadow_unrelated)]
fn recompute(a: u32, b: u32) -> (u32, u32) {
(a * 2, b * 4)
}
fn main() {
let (mut start, mut end) = (12, 15);
println!("{start}, {end}");
(start, end) = recompute(start, end); // Lint flags this line
println!("{start}, {end}");
}
```
I saw this happen:
```
warning: `end` shadows a previous, unrelated binding
--> src/main.rs:10:13
|
10 | (start, end) = recompute(start, end);
| ^^^
|
note: previous binding is here
--> src/main.rs:10:6
|
10 | (start, end) = recompute(start, end);
| ^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated
```
I expected to see this happen:
No warnings should appear
Additional note:
If I change the flagged line to `let (start, end) = ...` (and remove the now-unnecessary `mut`s), clippy is happy even though both `start` and `end` are indeed being shadowed (albeit not unrelated). So the issue seems to be related specifically to this destructuring assignment.
### Version
```text
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
```
### Additional Labels
_No response_
Thank you, somehow I didn't see that.