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

Weird compiler reporting when for is forgotten #8128

Closed
Seldaek opened this issue Jul 30, 2013 · 3 comments
Closed

Weird compiler reporting when for is forgotten #8128

Seldaek opened this issue Jul 30, 2013 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Jul 30, 2013

I don't know if it's fixable, but it would be nice if the ... || {} syntax created an error when it doesn't make sense (or does it and I am confused?)

To reproduce, try to compile:

fn main() {
    let test = [0, 1];
    test.iter().advance |val| {
        println(arg);
    }
}

As you see for is missing at line 3, but the compiler reports:

test.rs:3:25: 3:28 error: unresolved name `val`. Did you mean `test`?
test.rs:3     test.iter().advance |val| {
                                   ^~~
test.rs:4:16: 4:19 error: unresolved name `arg`. Did you mean `test`?
test.rs:4         println(arg);
                          ^~~

Which is very misleading.

@thestinger
Copy link
Contributor

The old for syntax is gone, but the error reporting here could still likely be improved. I don't really understand why that's making it past the parser to resolve.

@huonw
Copy link
Member

huonw commented Nov 18, 2013

Triage: still the same message.

It's parsing it as (test.iter().advance) BIT_OR val BIT_OR ({ println(arg); }), since blocks are expressions, and all that.

@alexcrichton
Copy link
Member

This bug is quite old at this point, and for loops have progressed quite a bit since that point, so I'm going to close this for now as we definitely shouldn't be recommending for there any more!

flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 30, 2021
changelog: Fix error suggestion of skip(..).next() for immutable variable.
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 30, 2021
Fix 8128

Fixes rust-lang#8128

changelog: Fix  error suggestion of `skip(..).next()` for immutable variable.
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

4 participants