diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-21 19:36:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-21 19:36:53 +0100 |
| commit | d3649f8d52c9e6d7b1877f6d6781d31c356b76af (patch) | |
| tree | e99287990f2919c8df14442313c7487a41e1f5a0 /compiler/rustc_parse/src/parser | |
| parent | f3a1a8cd4fbc0d277cc85a2dd8edf937a3af52e6 (diff) | |
| parent | 76ea56667703ac06689ff1d6fba5d170fa7392a7 (diff) | |
| download | rust-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.rs | 10 |
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()); |
