-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.
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
| if let ExprKind::Let(..) = cond.kind { | |
| // Remove the last feature gating of a `let` expression since it's stable. | |
| this.sess.gated_spans.ungate_last(sym::let_chains, cond.span); | |
| let span = if_span.to(cond.span); | |
| this.sess.gated_spans.gate(sym::if_let_guard, span); | |
| } |
We only gate it under if_let_guard if the let is directly under the guard node.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.