diff --git a/tests/ui/liveness/unused-assignments-match-guard-issue-80954.rs b/tests/ui/liveness/unused-assignments-match-guard-issue-80954.rs new file mode 100644 index 0000000000000..0093eacc31f14 --- /dev/null +++ b/tests/ui/liveness/unused-assignments-match-guard-issue-80954.rs @@ -0,0 +1,24 @@ +// Regression test for https://github.com/rust-lang/rust/issues/80954 +// Rustc diagnostics should recognize that +// the assignment to 'x' and 'n' are being used +//@ check-pass + +fn main() { + let mut x = 0; + match () { + () if { + x = 42; + false + } => {} + _ => { + println!("{}", x); + } + } + + let mut n = 0; + match 0 { + | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ | _ if + { println!("{}", n); n += 1; false } => {} + _ => {} + } +}