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

Diagnostic when using moved value in loop{} could be clearer #31874

Closed
vi opened this issue Feb 24, 2016 · 5 comments
Closed

Diagnostic when using moved value in loop{} could be clearer #31874

vi opened this issue Feb 24, 2016 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@vi
Copy link
Contributor

vi commented Feb 24, 2016

Consider this error message:

struct Qqq;
fn consume(_:Qqq){}
fn main() {
    let a = Qqq;
    consume(a);
    consume(a);
}
<anon>:6:13: 6:14 error: use of moved value: `a` [E0382]
<anon>:6     consume(a);
                     ^
<anon>:5:13: 5:14 note: `a` moved here because it has type `Qqq`, which is non-copyable
<anon>:5     consume(a);

It look more or less clear. But if we move and try to use on the same line:

struct Qqq;
fn consume(_:Qqq){}
fn main() {
    let a = Qqq;
    loop {
        consume(a);
    }
}

the diagnostic looks less clear:

<anon>:6:17: 6:18 error: use of moved value: `a` [E0382]
<anon>:6         consume(a);
                         ^
<anon>:6:17: 6:18 help: see the detailed explanation for E0382
note: `a` was previously moved here (where?) because it has type `Qqq`, which is non-copyable

Note the absence of filename and line number.

Maybe it should point to the same line <anon>:6 or there should dedicated message mentioning the loop...

@huonw huonw changed the title Diagnostic when using moved value in loop{} may be metter Diagnostic when using moved value in loop{} could be clearer Feb 25, 2016
@huonw huonw added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 25, 2016
@jonas-schievink
Copy link
Contributor

How about:

<anon>:6:17: 6:18 note: `a` was possibly moved here earlier because this expression may be evaluated multiple times
<anon>:6:17: 6:18 note: `a` was moved because it has type `Qqq`, which is non-copyable

Special-casing loops seems hard to do, but this might be enough to clarify what's going on.

@birkenfeld
Copy link
Contributor

Duplicate of #10876.

@estebank
Copy link
Contributor

This was fixed in 5b150cf.

@arielb1
Copy link
Contributor

arielb1 commented Jun 18, 2016

Fixed? The error message is the same modulo formatting.

Testing it again - the moveck error message mentions "previous iteration", but not the borrowck.

@arielb1
Copy link
Contributor

arielb1 commented Jun 18, 2016

Closing the moveck issue.

@arielb1 arielb1 closed this as completed Jun 18, 2016
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

6 participants