Fix unsoundness in iterator Clone impl (crudely) #120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.