Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Emerentius opened this issue Aug 1, 2018 · 1 comment
Closed

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

Emerentius opened this issue Aug 1, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Emerentius
Copy link
Contributor

Emerentius commented Aug 1, 2018

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.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 1, 2018
@estebank
Copy link
Contributor

Duplicate of #36611

@estebank estebank marked this as a duplicate of #36611 Sep 19, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Sep 22, 2018
Detect `for _ in in bar {}` typo

Fix rust-lang#36611, rust-lang#52964, without modifying the parsing of emplacement `in` to avoid further problems like rust-lang#50832.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants