Closed tyilo closed 3 weeks ago
This was going to be implemented in #152, but was discovered to possibly be unsound in general (https://github.com/Lokathor/bytemuck/pull/152#issuecomment-1336252308), so a never-unsound-but-more-conservative implementation was implemented instead (#160, require T to be AnyBitPattern
so we know it has no interior mutability).If Freeze
was stable, then this would be possible (either impl<T: Freeze + Copy + 'static> AnyBitPattern for MaybeUninit<T>
, or under #153, impl<T> AnyBitPattern for MaybeUninit<T>
).
Ah, so this is only sound if implementing Copy
means a type also implements Freeze
.
As I understand it, there are currently no !Freeze
type that implements Copy
so this change would be sound for the current version of Rust.
However this could change in a future version of Rust, where this change would then be unsound.
I've heard occasional rumblings of wanting Freeze to be a a stable trait some day. It wouldn't be any time soon, but more people are coming around to it being quite useful. So, I think that we should wait until that happens.
I'm going to close this until Rust as a language develops further, and then maybe someday later we can revisit the concept.
MaybeUninit<T>
is always valid for any bit pattern even ifT
is not.