about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2023-08-28 10:31:45 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2023-08-28 10:31:45 +0100
commit89235fd8379d6b1b0bcea704e162ba3d314906da (patch)
tree2615afdb510de2c85caf520d956cba806565b687
parent56c17dc280c32112a9adf2cc69c845aa90d18dc4 (diff)
downloadrust-89235fd8379d6b1b0bcea704e162ba3d314906da.tar.gz
rust-89235fd8379d6b1b0bcea704e162ba3d314906da.zip
Allow stuct literals in if let guards
This is consistent with normal match guards.
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs4
-rw-r--r--tests/ui/parser/struct-literal-in-match-guard.rs3
2 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 9ae3ef6172c..5898c6565e6 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2477,9 +2477,7 @@ impl<'a> Parser<'a> {
         } else {
             self.expect(&token::Eq)?;
         }
-        let expr = self.with_res(self.restrictions | Restrictions::NO_STRUCT_LITERAL, |this| {
-            this.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())
-        })?;
+        let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?;
         let span = lo.to(expr.span);
         self.sess.gated_spans.gate(sym::let_chains, span);
         Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
diff --git a/tests/ui/parser/struct-literal-in-match-guard.rs b/tests/ui/parser/struct-literal-in-match-guard.rs
index bf0551b5c97..bbee60e2817 100644
--- a/tests/ui/parser/struct-literal-in-match-guard.rs
+++ b/tests/ui/parser/struct-literal-in-match-guard.rs
@@ -3,6 +3,8 @@
 // Unlike `if` condition, `match` guards accept struct literals.
 // This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>.
 
+#![feature(if_let_guard)]
+
 #[derive(PartialEq)]
 struct Foo {
     x: isize,
@@ -11,6 +13,7 @@ struct Foo {
 fn foo(f: Foo) {
     match () {
         () if f == Foo { x: 42 } => {}
+        () if let Foo { x: 0.. } = Foo { x: 42 } => {}
         _ => {}
     }
 }