From 76ea56667703ac06689ff1d6fba5d170fa7392a7 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 21 Feb 2022 08:27:24 +0100 Subject: Better error if the user tries to do assignment ... else --- compiler/rustc_parse/src/parser/stmt.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'compiler/rustc_parse/src/parser') 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), + " ... 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()); -- cgit 1.4.1-3-g733a5