I wonder why is there ManuallyDrop in MaybeUninit?
Why is it ManuallyDrop? I've thought that Drop is never called for unions?
Is the ManuallyDrop needed for anything safety related?
@rkruppe so drop is called after all?
Oh so it's not meant for safety, but for forward compatibility?
For a possible future where that RFC is implemented and stabilized
As then e.g. MaybeUninit<Vec<u32>> would not be allowed any more?
The point of disallowing union fields with drop glue is so we never have to worry about what that means and can simply never call drop union fields without that being a massive surprise and footgun
but that doesn't answer my question: Is the presence of ManuallyDrop is for forwards compatibility only, to keep MaybeUninit<Vec<u32>> working even after the RFC is implemented?
I guess it's yes.
Oh I guess if it's not implemented yet, then it's technically for forward compatibility yes
Sorry for misunderstanding
Thanks, that's what I wanted to know!
ManuallyDrop is not just for compatibility
ManuallyDrop works with unsized types. And
Option<ManuallyDrop<Vec<u8>>> gets layout optimizations
"I may have totally uninitialized data" vs "I want to control dropping" are not the same concerns
having uninitialized data implies you need to control dropping (hence
MaybeUninit does not auto-drp), but not vice versa