I was recently disappointed to find out that you cannot use MaybeUninit
in union fields (if T: !Copy
).
Only Copy
fields or fields wrapped in ManuallyDrop
are allowed (or tuples/arrays of allowed types).
union Example<T> {
// this is not allowed, must be ManuallyDrop<MaybeUninit<T>>
inline: MaybeUninit<T>,
alloc: *mut T,
}
ManuallyDrop<MaybeUninit<T>>
is redundant as MaybeUninit
already internally wraps T
in ManuallyDrop
. Nothing happens when MaybeUninit
is dropped.
Could the rules be relaxed to allow MaybeUninit
union fields?
Relevant Code: