about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2022-02-21 08:27:24 +0100
committerest31 <MTest31@outlook.com>2022-02-21 08:59:39 +0100
commit76ea56667703ac06689ff1d6fba5d170fa7392a7 (patch)
tree9ac376f716daa1c81e1285bc7bdf837b0a064617 /compiler/rustc_parse/src/parser
parentc1aa85475cf5623caf50f7ef3b62903bb084e518 (diff)
downloadrust-76ea56667703ac06689ff1d6fba5d170fa7392a7.tar.gz
rust-76ea56667703ac06689ff1d6fba5d170fa7392a7.zip
Better error if the user tries to do assignment ... else
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());