The path statement leaves the value move-from?

Amazingly valid piece of code:

let p = &mut 1i;
p; // note: `p` moved here because it has type `&mut int`, which is non-copyable
p; // error: use of moved value: `p`

Is this a mistake or an alleged behavior?

+4
source share
1 answer

He intended. &mut Tis a type of its own, so when you mention it as an expression, it moves. You usually don’t notice this, because method calls have their own enumeration rules that give the called temporary mutable borrow value self(to avoid annoying your mutable reference).

+2
source

All Articles