Skip to content

Don't suggest adding in to a for loop that already has one#157917

Open
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-for-loop-missing-in-suggestion-103561
Open

Don't suggest adding in to a for loop that already has one#157917
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-for-loop-missing-in-suggestion-103561

Conversation

@onehr

@onehr onehr commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Closes #103561.

When a for loop is missing its in, the parser suggested inserting one based only on the token following the pattern. For a malformed binding such as for i i in 0..10 it therefore suggested for i in i in 0..10, which is itself invalid.

The suggestion is now only emitted when the loop header does not already contain an in before the body. The for x EXPR / for x of EXPR / for x = EXPR suggestions are unchanged.

When a `for` loop is missing its `in`, the parser suggested inserting one
based only on the token after the pattern. A malformed binding such as
`for i i in 0..10` was therefore "corrected" to `for i in i in 0..10`,
which does not parse. Only suggest inserting `in` when the loop header
does not already contain one before the body.
@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 15, 2026
@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, parser
  • compiler, parser expanded to 73 candidates
  • Random selection from 21 candidates

@onehr onehr marked this pull request as draft June 15, 2026 13:32
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 15, 2026
@onehr onehr marked this pull request as ready for review June 16, 2026 05:08
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for validity of next few tokens before suggesting adding missing in in for loop

3 participants