Skip to content

Improving error for unnecessary parentheses in for loop head #62724

Closed
@badboy

Description

@badboy

The following code:

fn main() {
    let v = vec![1,2,3];
    
    for (x in v) { }
}

leads to this error:

error: expected one of `)`, `,`, or `@`, found `in`
 --> src/main.rs:4:12
  |
4 |     for (x in v) { }
  |            ^^ expected one of `)`, `,`, or `@` here

(playground)

A colleague of mine typed this code, coming with a C++/JavaScript/Kotlin background where parentheses are required in the for loop head.

I wonder if it’s possible/worth it to make that error message nicer and easier to understand. (@estebank asked me to file this issue, so it doesn't get lost)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions