Skip to content

Improve error message for missing parens in tuple destructure in for loop #48492

Closed
@comex

Description

@comex

Given:

    for foo, bar in [(1, 2), (3, 4)] {}

rustc produces:

error: missing `in` in `for` loop
  --> src/main.rs:44:12
   |
44 |     for foo, bar in [(1, 2)] {}
   |            ^ help: try adding `in` here

error: expected expression, found `,`
  --> src/main.rs:44:12
   |
44 |     for foo, bar in [(1, 2)] {}
   |            ^

…but it would be better if it figured out that the user presumably intended for (foo, bar) in ..., and gave a more specific error message.

This is probably a somewhat common error coming from Python, which has similar syntax for for loops but allows omitting the parentheses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions