Rollup merge of #150460 - RalfJung:miri-manually-drop, r=dtolnay

fix ManuallyDrop::into_inner aliasing (Miri) issues

Fixes https://github.com/rust-lang/miri/issues/4793

r? `@WaffleLapkin`
This commit is contained in:
Jonathan Brouwer
2025-12-28 18:16:11 +01:00
committed by GitHub
2 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -200,7 +200,9 @@ pub const fn new(value: T) -> ManuallyDrop<T> {
#[rustc_const_stable(feature = "const_manually_drop", since = "1.32.0")]
#[inline(always)]
pub const fn into_inner(slot: ManuallyDrop<T>) -> T {
slot.value.into_inner()
// Cannot use `MaybeDangling::into_inner` as that does not yet have the desired semantics.
// SAFETY: We know this is a valid `T`. `slot` will not be dropped.
unsafe { (&raw const slot).cast::<T>().read() }
}
/// Takes the value from the `ManuallyDrop<T>` container out.
@@ -0,0 +1,3 @@
fn main() {
let _ = std::panic::catch_unwind(|| Box::<str>::from("..."));
}