Better error if the user tries to do assignment ... else
This commit is contained in:
parent
c1aa85475c
commit
76ea566677
3 changed files with 45 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue