From 7a752788367d06e4bc20351e5235bea8c11667b4 Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Fri, 3 Feb 2023 12:23:37 +0300 Subject: [PATCH 1/2] Recover from missing expression in for loop --- .../rustc_error_messages/locales/en-US/parse.ftl | 3 +++ compiler/rustc_parse/src/errors.rs | 12 ++++++++++++ compiler/rustc_parse/src/parser/expr.rs | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/compiler/rustc_error_messages/locales/en-US/parse.ftl b/compiler/rustc_error_messages/locales/en-US/parse.ftl index 244eb41eb39..2ef3dba557e 100644 --- a/compiler/rustc_error_messages/locales/en-US/parse.ftl +++ b/compiler/rustc_error_messages/locales/en-US/parse.ftl @@ -128,6 +128,9 @@ parse_missing_in_in_for_loop = missing `in` in `for` loop .use_in_not_of = try using `in` here instead .add_in = try adding `in` here +parse_missing_expression_in_for_loop = missing expression to iterate on in `for` loop + .suggestion = try adding an expression to the `for` loop + parse_missing_comma_after_match_arm = expected `,` following `match` arm .suggestion = missing a comma here to end this `match` arm diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index fd4333dbbec..fc7c839f1c4 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -433,6 +433,18 @@ pub(crate) enum MissingInInForLoopSub { AddIn(#[primary_span] Span), } +#[derive(Diagnostic)] +#[diag(parse_missing_expression_in_for_loop)] +pub(crate) struct MissingExpressionInForLoop { + #[primary_span] + #[suggestion( + code = "/* expression */ ", + applicability = "has-placeholders", + style = "verbose" + )] + pub span: Span, +} + #[derive(Diagnostic)] #[diag(parse_missing_comma_after_match_arm)] pub(crate) struct MissingCommaAfterMatchArm { 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 @@ fn parse_for_expr(&mut self, opt_label: Option