-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
fn main() {
let x = Arc::new(1);
foo(x);
bar(x);
}
fn foo(_: Arc<usize>) {}
fn bar(_: Arc<usize>) {}
error[[E0382]](https://doc.rust-lang.org/stable/error-index.html#E0382): use of moved value: `x`
--> src/main.rs:6:9
|
4 | let x = Arc::new(1);
| - move occurs because `x` has type `std::sync::Arc<usize>`, which does not implement the `Copy` trait
5 | foo(x);
| - value moved here
6 | bar(x);
| ^ value used here after move
The help message could mention that Arc
implements Clone
. We don't usually suggest cloning values in diagnostics, but for Arc/Rc
we probably should.
Another common case (this one is probably harder to suggest a fix for):
fn main() {
let x = Arc::new(1);
for _ in 0..4 {
std::thread::spawn(move || {
println!("{}", x);
});
}
}
error[[E0382]](https://doc.rust-lang.org/stable/error-index.html#E0382): use of moved value: `x`
--> src/main.rs:6:28
|
4 | let x = Arc::new(1);
| - move occurs because `x` has type `std::sync::Arc<i32>`, which does not implement the `Copy` trait
5 | for _ in 0..4 {
6 | std::thread::spawn(move || {
| ^^^^^^^ value moved into closure here, in previous iteration of loop
7 | println!("{}", x);
| - use occurs due to use in closure
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.