For function call, does compiler treat move as copy for '&mut T' type?

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 i32 = &mut i;
	let x: &mut i32 = j;
	let y: &mut i32 = 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?

Your question is better suited for This forum is meant for discussions about compiler internals and changes to the language or standard library.

Got it, thanks. But do you know how can I close this post?

Flag the topic and ask the moderators to close it. (I went ahead and did that so you shouldn't need to this time.)

1 Like

Closing, as requested. The topic on URLO is here: