This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 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> {
833833 #[ unstable( feature = "maybe_uninit_array_assume_init" , issue = "80908" ) ]
834834 #[ inline( always) ]
835835 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-
842836 // 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
846841 unsafe {
847842 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 ( )
851844 }
852845 }
853846
You can’t perform that action at this time.
0 commit comments