Skip to content

confusing error message in for-loop with duplicate in #52964

Closed
@Emerentius

Description

@Emerentius

When accidentally writing for x in in iter with a duplicate in, the error message will point to the first thing beneath the loop body with a confusing error message.

Example:

fn main() {
    let i = ();
    for x in in 0..1 {}
    i;
}

results in

error: expected one of `{` or an operator, found `i`
 --> src/main.rs:4:5
  |
3 |     for x in in 0..1 {}
  |                         - expected one of `{` or an operator here
4 |     i;
  |     ^ unexpected token

This is probably because in 0..1 {} is parsed as the old emplacement syntax (in PLACE { BLOCK }). And because the block has been parsed as part of the emplacement, the loop is seen as having no block.

When another block is added (for x in in 0..1 {} {}), the error message tells us that this emplacement syntax is obsolete.

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