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
commit 2ecaa1df2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -200,7 +200,9 @@ impl<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.

View file

@ -0,0 +1,3 @@
fn main() {
let _ = std::panic::catch_unwind(|| Box::<str>::from("..."));
}