Doesn't std::mem::replace violate ownership rules?

117 points hshlgpw

I'm looking at the \std::mem::replace\\ here.

If I understand correctly, from a mutable reference, I can get ownership of the current value (and swap it with another thing). That sounds quite odd.

If \T\\ has the \Copy\\ trait bound, it sounds fine, but if \T\\ has move semantics if feels that if I give a mutable reference to some random function, that function can drop my value and replace it with some other garbage.

So actually, it doesn't feel that when giving a mutable reference, I own the \Drop\\ control of the value.

What am I missing here?