Skip to content

Commit 89235fd

Browse files
committed
Allow stuct literals in if let guards
This is consistent with normal match guards.
1 parent 56c17dc commit 89235fd

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: compiler/rustc_parse/src/parser/expr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2477,9 +2477,7 @@ impl<'a> Parser<'a> {
24772477
} else {
24782478
self.expect(&token::Eq)?;
24792479
}
2480-
let expr = self.with_res(self.restrictions | Restrictions::NO_STRUCT_LITERAL, |this| {
2481-
this.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())
2482-
})?;
2480+
let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?;
24832481
let span = lo.to(expr.span);
24842482
self.sess.gated_spans.gate(sym::let_chains, span);
24852483
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))

Diff for: tests/ui/parser/struct-literal-in-match-guard.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Unlike `if` condition, `match` guards accept struct literals.
44
// This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>.
55

6+
#![feature(if_let_guard)]
7+
68
#[derive(PartialEq)]
79
struct Foo {
810
x: isize,
@@ -11,6 +13,7 @@ struct Foo {
1113
fn foo(f: Foo) {
1214
match () {
1315
() if f == Foo { x: 42 } => {}
16+
() if let Foo { x: 0.. } = Foo { x: 42 } => {}
1417
_ => {}
1518
}
1619
}

0 commit comments

Comments
 (0)