diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-09 13:58:54 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-09 13:58:54 +1000 |
| commit | aea608c751238e6d9280658ccfb867c4e135b67c (patch) | |
| tree | c030e8f7d759eccccd1b6e9d32d1d50584529db5 /compiler/rustc_parse/src | |
| parent | a56142cbfbcd9b1506f7f18431de09b15f7adbb3 (diff) | |
| parent | b2d524c43d113bba72e0a23b4a97cbbeb6eb39bb (diff) | |
| download | rust-aea608c751238e6d9280658ccfb867c4e135b67c.tar.gz rust-aea608c751238e6d9280658ccfb867c4e135b67c.zip | |
Rollup merge of #145124 - compiler-errors:for-eq, r=lqd
Recover `for PAT = EXPR {}`
I type this constantly, and the existing suggestion to put `in` before the `=` is misleading.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 48ff0394d46..ddb2c545c78 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -585,14 +585,13 @@ pub(crate) struct MissingInInForLoop { #[derive(Subdiagnostic)] pub(crate) enum MissingInInForLoopSub { + // User wrote `for pat of expr {}` // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect - #[suggestion( - parse_use_in_not_of, - style = "verbose", - applicability = "maybe-incorrect", - code = "in" - )] + #[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")] InNotOf(#[primary_span] Span), + // User wrote `for pat = expr {}` + #[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")] + InNotEq(#[primary_span] Span), #[suggestion(parse_add_in, style = "verbose", applicability = "maybe-incorrect", code = " in ")] AddIn(#[primary_span] Span), } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 35b987cf50f..cbf6b78431c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3028,6 +3028,8 @@ impl<'a> Parser<'a> { let span = self.token.span; self.bump(); (span, errors::MissingInInForLoopSub::InNotOf) + } else if self.eat(exp!(Eq)) { + (self.prev_token.span, errors::MissingInInForLoopSub::InNotEq) } else { (self.prev_token.span.between(self.token.span), errors::MissingInInForLoopSub::AddIn) }; |
