Skip to content

Commit 47d5dcc

Browse files
committed
Use pointer casts instead of transmute
Signed-off-by: Joe Richey <joerichey@google.com>
1 parent ebc54de commit 47d5dcc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// except according to those terms.
88
#![allow(dead_code)]
99
use core::{
10-
mem::{self, MaybeUninit},
10+
mem::MaybeUninit,
1111
ptr,
1212
sync::atomic::{AtomicUsize, Ordering::Relaxed},
1313
};
@@ -73,7 +73,7 @@ impl LazyBool {
7373
#[inline(always)]
7474
pub unsafe fn slice_assume_init_mut<T>(slice: &mut [MaybeUninit<T>]) -> &mut [T] {
7575
// SAFETY: `MaybeUninit<T>` is guaranteed to be layout-compatible with `T`.
76-
mem::transmute(slice)
76+
&mut *(slice as *mut [MaybeUninit<T>] as *mut [T])
7777
}
7878

7979
#[inline]
@@ -87,7 +87,7 @@ pub fn slice_as_uninit<T>(slice: &[T]) -> &[MaybeUninit<T>] {
8787
// SAFETY: `MaybeUninit<T>` is guaranteed to be layout-compatible with `T`.
8888
// There is no risk of writing a `MaybeUninit<T>` into the result since
8989
// the result isn't mutable.
90-
unsafe { mem::transmute(slice) }
90+
unsafe { &*(slice as *const [T] as *const [MaybeUninit<T>]) }
9191
}
9292

9393
/// View an mutable initialized array as potentially-uninitialized.
@@ -97,5 +97,5 @@ pub fn slice_as_uninit<T>(slice: &[T]) -> &[MaybeUninit<T>] {
9797
#[inline(always)]
9898
pub unsafe fn slice_as_uninit_mut<T>(slice: &mut [T]) -> &mut [MaybeUninit<T>] {
9999
// SAFETY: `MaybeUninit<T>` is guaranteed to be layout-compatible with `T`.
100-
mem::transmute(slice)
100+
&mut *(slice as *mut [T] as *mut [MaybeUninit<T>])
101101
}

0 commit comments

Comments
 (0)