File tree 1 file changed +5
-12
lines changed
1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -833,21 +833,14 @@ impl<T> MaybeUninit<T> {
833
833
#[ unstable( feature = "maybe_uninit_array_assume_init" , issue = "80908" ) ]
834
834
#[ inline( always) ]
835
835
pub unsafe fn array_assume_init < const N : usize > ( array : [ Self ; N ] ) -> [ T ; N ] {
836
- // Convert using a union because mem::transmute does not support const_generics
837
- union ArrayInit < T , const N : usize > {
838
- maybe_uninit : ManuallyDrop < [ MaybeUninit < T > ; N ] > ,
839
- init : ManuallyDrop < [ T ; N ] > ,
840
- }
841
-
842
836
// SAFETY:
843
- // * The caller guarantees that all elements of the array are initialized,
844
- // * `MaybeUninit<T>` and T are guaranteed to have the same layout,
845
- // Therefore the conversion is safe
837
+ // * The caller guarantees that all elements of the array are initialized
838
+ // * `MaybeUninit<T>` and T are guaranteed to have the same layout
839
+ // * MaybeUnint does not drop, so there are no double-frees
840
+ // And thus the conversion is safe
846
841
unsafe {
847
842
intrinsics:: assert_inhabited :: < T > ( ) ;
848
-
849
- let array = ArrayInit { maybe_uninit : ManuallyDrop :: new ( array) } ;
850
- ManuallyDrop :: into_inner ( array. init )
843
+ ( & array as * const _ as * const T ) . read ( )
851
844
}
852
845
}
853
846
You can’t perform that action at this time.
0 commit comments