Skip to content

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

Description

@Rageking8

Given the following code: link

fn main() {
    for i i in 0..10 {

    }
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: missing `in` in `for` loop
 --> src/main.rs:2:10
  |
2 |     for i i in 0..10 {
  |          ^ help: try adding `in` here

error: expected `{`, found keyword `in`
 --> src/main.rs:2:13
  |
2 |     for i i in 0..10 {
  |             ^^ expected `{`

error: could not compile `playground` due to 2 previous errors

Ideally the compiler should check the validity of next few tokens in the source code before emitting an error of ( missing in in for loop ). If wanted we can even suggest adding a _ to delimit the identifier, though if might not be worth the effort. Thanks.

@rustbot label +D-invalid-suggestion +D-confusing

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions