Description
Since TakeOwnCell
doesn't put its data inside a MaybeUninit
, this means that that data always has to satisfy the validity requirements of that type.
But since that value can be moved away, it might not.
For example, if we create a TakeOwnCell<Box<u32>>
, take the box, and then deallocate the box, the data inside the empty TakeOwnCell
would hold a pointer to freed memory, which makes it invalid.
I tried to confirm this with miri, but my miri tests passed. I'm not sure why - Maybe I missed something, or maybe this causes the violation to not be found because it's not marked dereferencable
because of the UnsafeCell
(But I also tried with an older version of miri and it also passed).
However If I didn't misunderstand anything this is still UB.
This can be fixed by putting the data inside a MaybeUninit
, since moved away values are basically the same as uninitialized values.