mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-23 23:50:25 +08:00
20 lines
796 B
Plaintext
20 lines
796 B
Plaintext
|
$ cargo run
|
||
|
Compiling shared-state v0.1.0 (file:///projects/shared-state)
|
||
|
error[E0382]: use of moved value: `counter`
|
||
|
--> src/main.rs:9:36
|
||
|
|
|
||
|
5 | let counter = Mutex::new(0);
|
||
|
| ------- move occurs because `counter` has type `Mutex<i32>`, which does not implement the `Copy` trait
|
||
|
...
|
||
|
9 | let handle = thread::spawn(move || {
|
||
|
| ^^^^^^^ value moved into closure here, in previous iteration of loop
|
||
|
10 | let mut num = counter.lock().unwrap();
|
||
|
| ------- use occurs due to use in closure
|
||
|
|
||
|
error: aborting due to previous error
|
||
|
|
||
|
For more information about this error, try `rustc --explain E0382`.
|
||
|
error: could not compile `shared-state`
|
||
|
|
||
|
To learn more, run the command again with --verbose.
|