You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unused_assignments lint has trouble tracking that one match guard observes assignment from another match guard. #138069
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?"
Fun fact: This problem seems like it has been present for the entirety of Rust's support for assignments in pattern guards: I see the same false positive from the lint in Rust 1.39. (And in Rust 1.38, the code is rejected because at that time, assignments in pattern guards were illegal).
The liveness analysis that powers the unused assignments lint is pretty brittle. Ideally we'd reimplement it on the MIR with a real cfg-aware analysis so that we don't have disagreements between MIR's "uninitialized assignments" and this.
Activity
pnkfelix commentedon Mar 5, 2025
Fun fact: This problem seems like it has been present for the entirety of Rust's support for assignments in pattern guards: I see the same false positive from the lint in Rust 1.39. (And in Rust 1.38, the code is rejected because at that time, assignments in pattern guards were illegal).
compiler-errors commentedon Mar 5, 2025
The liveness analysis that powers the unused assignments lint is pretty brittle. Ideally we'd reimplement it on the MIR with a real cfg-aware analysis so that we don't have disagreements between MIR's "uninitialized assignments" and this.
cjgillot commentedon Oct 13, 2025
Fixed by #142390
KaiTomotake commentedon Jan 18, 2026
@rustbot claim
add lint test
add lint test
Rollup merge of rust-lang#151302 - add-lint-test, r=lqd
Unrolled build for #151302