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

Improve error message foo was previously moved here because it has type bar, which is non-copyable #32333

Closed
Yoric opened this issue Mar 18, 2016 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Yoric
Copy link
Contributor

Yoric commented Mar 18, 2016

I was recently faced with the following error message and it took me a few minutes to figure out what was wrong:

tests/test_manager.rs:93:52: 93:57 error: use of moved value: `value` [E0382]
tests/test_manager.rs:93                                             value: value
                                                                            ^~~~~
tests/test_manager.rs:93:52: 93:57 help: run `rustc --explain E0382` to see a detailed explanation
note: `value` was previously moved here because it has type `foxbox_taxonomy::values::Value`, which is non-copyable

The error was that I was moving a value from inside a loop. I believe that the error message could be improved to

note: This code is executed in a loop or closure, so it needs to move `value` each time
it reaches this point. This would only be possible if the type of `value` was copyable
but `value` has type `foxbox_taxonomy::values::Value`, which is non-copyable.
Perhaps you forgot to call `value.clone()`?
@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 17, 2016
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

I believe this is fixed today. We note that the value was moved in a previous iteration of the loop; though we could suggest calling clone() still... opened #42446 to track that.

fn main() {
    let a = String::new();
    loop {
        a;
    }
}
error[E0382]: use of moved value: `a`
 --> test.rs:4:9
  |
4 |         a;
  |         ^ value moved here in previous iteration of loop
  |
  = note: move occurs because `a` has type `std::string::String`, which does not implement the `Copy` trait

error: aborting due to previous error(s)

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants