Logical move == physical move?


This question has arisen from another one, but I decided to make it more generic.
So the question is. Does logical move of arbitrary value always means physical memory move?
If so, is there a way to prevent such move with owned values?
I'm talking about corner case where value is stored in custom allocated memory, then retrieved via ptr::read or the like, and them self-moving method is invoked. The closest example is FnOnce.
Will we have there:
a) 0 moves, final FnOnce code references memory at initial pointer site
b) 1 move, value bits are copied out of ptr onto stack
c) 2 moves, first onto local stack and then into FnOnce invocation


1 Like

Moves are semantically a memcpy. However, the compiler may optimize them out, depending.


Rust's current ABI actually passes anything larger than a pointer by-reference under the hood (this is not guaranteed/specified, it just happens to be the case today, and there are some exceptions like fat pointers which are also by-value). Similarly, I believe we secretly pass out-pointers for large returns (but I might be misremembering this).