mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 18:27:37 +00:00

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".
16 lines
564 B
Rust
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 },) => {}
|
|
_ => {}
|
|
}
|
|
}
|