rust/tests/ui/pattern/rfc-3637-guard-patterns/only-gather-locals-once.rs
dianne c343b2a47c gather_locals: only visit guard pattern guards when checking the guard
When checking a pattern with guards in it, `GatherLocalsVisitor` will
visit both the pattern (when type-checking the let, arm, or param
containing it) and the guard expression (when checking the guard
itself). This keeps it from visiting the guard when visiting the
pattern, since otherwise it would gather locals from the guard twice,
which would lead to a delayed bug: "evaluated expression more than
once".
2025-05-19 23:18:08 -07:00

16 lines
564 B
Rust

//@ check-pass
//! Test that `GatherLocalsVisitor` only visits expressions in guard patterns when checking the
//! expressions, and not a second time when visiting the pattern. If locals are declared inside the
//! the guard expression, it would ICE if visited twice ("evaluated expression more than once").
#![feature(guard_patterns)]
#![expect(incomplete_features)]
fn main() {
match (0,) {
// FIXME(guard_patterns): liveness lints don't work yet; this will ICE without the `_`.
(_ if { let _x = false; _x },) => {}
_ => {}
}
}