Closed saethlin closed 2 years ago
Looks good to me. ptr::read
keeps array
within a ManuallyDrop
, so there are no risks for double-drops if .clone()
panics. There are technically duplicate items in the array, but that's better than being uninitialized, and existing logic prevents double-drops there.
Published in 0.14.5
This example program is rejected by Miri, no
MIRIFLAGS
required:This is a problem for all types, it just requires no additional flags to Miri to trip the bug with a reference. The documentation for
MaybeUninit
says:The problem is that the copy loop may not initialize all the contents of
array
before.assume_init()
is called on it. In this example, none of the array is initialized.The theoretical proper fix is to keep the array elements as
MaybeUninit<T>
, but as far as I can tell that conflicts with the type bounds, and I can't find a way to resolve that. Therefore I've replaced theMaybeUninit
dance with just a bit-copy of the old array, then an element-wise clone of the elements we actually intend to copy. TheManuallyDrop
wrapper prevents this from turning into a double-drop.I'm not excited about this implementation, but I can't come up with anything else that compiles and is accepted by Miri.