Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::any::type_name;
use crate::clone::TrivialClone;
use crate::marker::Destruct;
use crate::mem::ManuallyDrop;
use crate::mem::{ManuallyDrop, transmute_neo};
use crate::{fmt, intrinsics, ptr, slice};

/// A wrapper type to construct uninitialized instances of `T`.
Expand Down Expand Up @@ -724,9 +724,9 @@ impl<T> MaybeUninit<T> {
// This also means that `self` must be a `value` variant.
unsafe {
intrinsics::assert_inhabited::<T>();
// We do this via a raw ptr read instead of `ManuallyDrop::into_inner` so that there's
// We do this via a transmute instead of `ManuallyDrop::into_inner` so that there's
// no trace of `ManuallyDrop` in Miri's error messages here.
(&raw const self.value).cast::<T>().read()
transmute_neo(self)
}
}

Expand Down
5 changes: 5 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,9 @@ pub const unsafe fn transmute_prefix<Src, Dst>(src: Src) -> Dst {
/// New version of `transmute`, exposed under this name so it can be iterated upon
/// without risking breakage to uses of "real" transmute.
///
/// Uses a `const`-`assert` to check the sizes instead of typeck hacks,
/// but is semantially identical to `transmute` otherwise.
///
/// It will not be stabilized under this name.
///
/// # Examples
Expand All @@ -1214,6 +1217,8 @@ pub const unsafe fn transmute_prefix<Src, Dst>(src: Src) -> Dst {
/// unsafe { transmute_neo::<u32, u16>(123) };
/// ```
#[unstable(feature = "transmute_neo", issue = "155079")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[inline]
pub const unsafe fn transmute_neo<Src, Dst>(src: Src) -> Dst {
const { assert!(Src::SIZE == Dst::SIZE) };

Expand Down
Loading