]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/array/mod.rs
Rollup merge of #75485 - RalfJung:pin, r=nagisa
[rust.git] / library / core / src / array / mod.rs
index cf3b9f8cce277afee374f71e2c375029bd8cecf0..6b28ab7d755631f68860ed2cd402f9d1cb20c418 100644 (file)
@@ -413,7 +413,8 @@ fn drop(&mut self) {
             }
         }
         let mut dst = MaybeUninit::uninit_array::<N>();
-        let mut guard: Guard<U, N> = Guard { dst: &mut dst as *mut _ as *mut U, initialized: 0 };
+        let mut guard: Guard<U, N> =
+            Guard { dst: MaybeUninit::first_ptr_mut(&mut dst), initialized: 0 };
         for (src, dst) in IntoIter::new(self).zip(&mut dst) {
             dst.write(f(src));
             guard.initialized += 1;
@@ -423,6 +424,6 @@ fn drop(&mut self) {
         crate::mem::forget(guard);
         // SAFETY: At this point we've properly initialized the whole array
         // and we just need to cast it to the correct type.
-        unsafe { (&mut dst as *mut _ as *mut [U; N]).read() }
+        unsafe { crate::mem::transmute_copy::<_, [U; N]>(&dst) }
     }
 }