Open
Description
I tried this code (playground):
fn pnk(x: usize) -> &'static str {
let mut k1 = "k1";
let mut h1 = "h1";
match x & 3 {
3 if { k1 = "unused?"; false } => (),
_ if { h1 = k1; true } => (),
_ => (),
}
h1
}
fn main() {
dbg!(pnk(3));
}
I expected to see this happen: No lint complaints about the assignment to k1
in the first match guard being "unused", since the assignment is subsequently observed by the second match guard.
Instead, this happened: The unused_assignments
lint has a false positive on the code above:
warning: value assigned to `k1` is never read
--> src/main.rs:5:16
|
5 | 3 if { k1 = "unused?"; false } => (),
| ^^
|
= help: maybe it is overwritten before being read?
= note: `#[warn(unused_assignments)]` on by default
warning: `playground` (bin "playground") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s
Running `target/debug/playground`
[src/main.rs:13:5] pnk(3) = "unused?"
Meta
I'm testing on the playground, Rust stable 1.85.0
Activity