Closed mwcampbell closed 7 months ago
It's possible to use mem::swap
to exchange the referenced value with something of the same type. Then the original value could be dropped.
So it's at least possible in a somewhat contrived scenario.
Ah, hadn't thought about mem::swap or equivalent. That makes sense.
I understand that dropping the underlying handle of a
Generic
source would lead to undefined behavior. But is it even possible to do that without requiring some unsafe code (besides the call toget_mut
itself)? For example,File
andOwnedFd
don't have aclose
method, or anything equivalent as far as I can tell. An example illustrating whyget_mut
itself has to be unsafe, that is, how one would be able to drop the underlying handle without any other unsafe code, would be helpful.