As we all know, any type that not impl Copy trait will move.
Below assignment statement is move:
{
let mut i = 0;
let j = &mut i; // `&mut i32` does not impl Copy trait
let x = j;
let y = j; // OK, use of moved value: `j`
}
Below function call is move:
{
struct I {}
fn consume(t: I) {}
let t: I = I {};
consume(t); // `I` does not impl Copy trait, so `t` is moved here.
t; // OK: we can not use `t` now
}
Below function call seems copy:
{
fn consume(t: &mut i32) {}
let mut i: i32 = 0;
let t: &mut i32 = &mut i;
consume(t); // `&mut i32` does not impl Copy trait, so `t` is moved here.
t; // QUESTION: `t` should be moved already, but why can we still use it?
}