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

Diagnostics should mention loop iteration #21752

Closed
aochagavia opened this issue Jan 29, 2015 · 3 comments
Closed

Diagnostics should mention loop iteration #21752

aochagavia opened this issue Jan 29, 2015 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@aochagavia
Copy link
Contributor

The code:

fn main() {
    let v: Vec<i32> = Vec::new();
    loop {
        drop(v);
    }
}

The error message:

<anon>:4:14: 4:15 error: use of moved value: `v`
<anon>:4         drop(v);
                      ^
<anon>:4:14: 4:15 note: `v` moved here because it has type `collections::vec::Vec<i32>`, which is non-copyable
<anon>:4         drop(v);
                      ^

In this simple example, it is pretty easy to notice that the error happens in the next iteration. However, usually the code is more complicated than this and the error is very confusing (see this reddit thread). Maybe we could add something like move happens in the next iteration of the loop.

@sinistersnare
Copy link
Contributor

I dont know, I feel like the error message makes perfect sense. This is just a case of learning the language and not knowing all (or a good amount of) error cases, in my opinion.

If we had error messages for everything like this, then compiler output would be inundated with crap that no one reads anyways.

@kmcallister kmcallister added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 29, 2015
@kmcallister kmcallister changed the title This code needs a better error message Diagnostics should mention loop iteration Jan 30, 2015
@kmcallister
Copy link
Contributor

Seems worth looking into improving these messages.

@birkenfeld
Copy link
Contributor

Duplicate of #10876.

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

5 participants