diff options
| author | bors <bors@rust-lang.org> | 2023-02-05 20:33:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-05 20:33:05 +0000 |
| commit | 75a0be98f25a4b9de5afa0e15eb016e7f9627032 (patch) | |
| tree | 7f417a69f7d64017ffabc3291f6d8adafbdad700 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | a67649675014546ce454d65bc8fe3ebd18e6a319 (diff) | |
| parent | 17b6bd6b70fd49c034b32b5b9b2869d139ed4d46 (diff) | |
| download | rust-75a0be98f25a4b9de5afa0e15eb016e7f9627032.tar.gz rust-75a0be98f25a4b9de5afa0e15eb016e7f9627032.zip | |
Auto merge of #107526 - obeis:for-missing-iterator, r=estebank,compiler-errors
Recover form missing expression in `for` loop Close #78537 r? `@estebank`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 473a5bb8cb8..c37808f8c3d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2471,6 +2471,21 @@ impl<'a> Parser<'a> { let pat = self.recover_parens_around_for_head(pat, begin_paren); + // Recover from missing expression in `for` loop + if matches!(expr.kind, ExprKind::Block(..)) + && !matches!(self.token.kind, token::OpenDelim(token::Delimiter::Brace)) + && self.may_recover() + { + self.sess + .emit_err(errors::MissingExpressionInForLoop { span: expr.span.shrink_to_lo() }); + let err_expr = self.mk_expr(expr.span, ExprKind::Err); + let block = self.mk_block(vec![], BlockCheckMode::Default, self.prev_token.span); + return Ok(self.mk_expr( + lo.to(self.prev_token.span), + ExprKind::ForLoop(pat, err_expr, block, opt_label), + )); + } + let (attrs, loop_block) = self.parse_inner_attrs_and_block()?; let kind = ExprKind::ForLoop(pat, expr, loop_block, opt_label); |
