Open
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