Skip to content

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

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
onehr:fix-for-loop-missing-in-suggestion-103561
Jun 18, 2026
Merged

Don't suggest adding in to a for loop that already has one#157917
rust-bors[bot] merged 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
@folkertdev

Copy link
Copy Markdown
Contributor

Thanks!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0ab14ca has been approved by folkertdev

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 17, 2026
…estion-103561, r=folkertdev

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

Closes rust-lang#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.
rust-bors Bot pushed a commit that referenced this pull request Jun 17, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #157788 (Accumulate multiple -Zsanitizer target modifiers)
 - #158012 (Stabilize `strip_circumfix`)
 - #157810 (Query the trait solver in slow path for `missing_debug_implementations`)
 - #157829 (tests: adapt two tests for LLVM 23 changes)
 - #157917 (Don't suggest adding `in` to a `for` loop that already has one)
 - #157967 (Preserve track_caller for by-value dyn vtable shims)
 - #158019 (delegation: add simple test for incremental compilation)
 - #158023 (Move `UnusedDuplicate` diag struct to `rustc_attr_parsing`)
rust-bors Bot pushed a commit that referenced this pull request Jun 17, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #157788 (Accumulate multiple -Zsanitizer target modifiers)
 - #158012 (Stabilize `strip_circumfix`)
 - #157810 (Query the trait solver in slow path for `missing_debug_implementations`)
 - #157829 (tests: adapt two tests for LLVM 23 changes)
 - #157873 (mips: set llvm_args -mno-check-zero-division for all mips targets)
 - #157886 (Reject extra fields in MGCA struct const arguments)
 - #157917 (Don't suggest adding `in` to a `for` loop that already has one)
 - #157967 (Preserve track_caller for by-value dyn vtable shims)
 - #158019 (delegation: add simple test for incremental compilation)
 - #158023 (Move `UnusedDuplicate` diag struct to `rustc_attr_parsing`)
 - #158029 (Rename `project-stable-mir` to `project-rustc-public`)
 - #158044 (Add more tests for parallel frontend issues)
@rust-bors rust-bors Bot merged commit abbab2d into rust-lang:main Jun 18, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 18, 2026
rust-timer added a commit that referenced this pull request Jun 18, 2026
Rollup merge of #157917 - onehr:fix-for-loop-missing-in-suggestion-103561, r=folkertdev

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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