Closed
Description
If you compile the following code:
fn main() {
match true {
_ if let true = true => {}
_ => {}
}
}
rustc complains as expected:
error[E0658]: `if let` guards are experimental
--> src/main.rs:3:11
|
5 | _ if let true = true => {}
| ^^^^^^^^^^^^^^^^^^
|
= note: see issue #51114 <https://github.com/rust-lang/rust/issues/51114> for more information
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
However, if I use the let_chains
feature, by e.g. wrapping the let true = true
in parentheses, or adding another clause, it compiles without error:
#![feature(let_chains)]
fn main() {
match true {
_ if let true = true && true => {}
_ => {}
}
}
It depends only on the let_chains
feature, instead of both let_chains
and if_let_guard
.
This is because here:
rust/compiler/rustc_parse/src/parser/expr.rs
Lines 2393 to 2398 in 523be2e
We only gate it under if_let_guard
if the let
is directly under the guard node.