about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-21 19:36:53 +0100
committerGitHub <noreply@github.com>2022-02-21 19:36:53 +0100
commitd3649f8d52c9e6d7b1877f6d6781d31c356b76af (patch)
treee99287990f2919c8df14442313c7487a41e1f5a0 /compiler/rustc_parse/src/parser
parentf3a1a8cd4fbc0d277cc85a2dd8edf937a3af52e6 (diff)
parent76ea56667703ac06689ff1d6fba5d170fa7392a7 (diff)
downloadrust-d3649f8d52c9e6d7b1877f6d6781d31c356b76af.tar.gz
rust-d3649f8d52c9e6d7b1877f6d6781d31c356b76af.zip
Rollup merge of #94211 - est31:let_else_destructuring_error, r=matthewjasper
Better error if the user tries to do assignment ... else

If the user tries to do assignment ... else, we now issue a more comprehensible error in the parser.

closes #93995
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/stmt.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs
index 227a9e37dbc..965e6a6ca3f 100644
--- a/compiler/rustc_parse/src/parser/stmt.rs
+++ b/compiler/rustc_parse/src/parser/stmt.rs
@@ -103,6 +103,16 @@ impl<'a> Parser<'a> {
             } else {
                 self.parse_expr_res(Restrictions::STMT_EXPR, Some(attrs))
             }?;
+            if matches!(e.kind, ExprKind::Assign(..)) && self.eat_keyword(kw::Else) {
+                let bl = self.parse_block()?;
+                // Destructuring assignment ... else.
+                // This is not allowed, but point it out in a nice way.
+                let mut err = self.struct_span_err(
+                    e.span.to(bl.span),
+                    "<assignment> ... else { ... } is not allowed",
+                );
+                err.emit();
+            }
             self.mk_stmt(lo.to(e.span), StmtKind::Expr(e))
         } else {
             self.error_outer_attrs(&attrs.take_for_recovery());