Closed
Description
The following code:
struct NotCopy;
fn main() {
let mut a = NotCopy;
loop {
|| {
&mut a;
a;
};
}
}
produces the following error:
error[E0382]: use of moved value: `a`
--> src/lib.rs:6:9
|
4 | let mut a = NotCopy;
| ----- move occurs because `a` has type `NotCopy`, which does not implement the `Copy` trait
5 | loop {
6 | || {
| ^^ value moved into closure here, in previous iteration of loop
7 | &mut a;
| - use occurs due to use in closure
However, the &mut a;
statement is not responsible for the move - it's the a;
statement below it which causes the move.
Meta
rustc --version --verbose
:
rustc 1.47.0-nightly (de521cbb3 2020-08-21)
binary: rustc
commit-hash: de521cbb303c08febd9fa3755caccd4f3e491ea3
commit-date: 2020-08-21
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0