Add drop check test & MaybeUninit::first_ptr_mut

Also in drop check test add hacky workaround for platforms that don't support
panic=unwind
This commit is contained in:
kadmin
2020-08-11 18:39:12 +00:00
parent 412417d807
commit af32db21c8
2 changed files with 32 additions and 2 deletions

View File

@@ -413,7 +413,8 @@ impl<T, const N: usize> [T; N] {
}
}
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 @@ impl<T, const N: usize> [T; N] {
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) }
}
}