diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 1b5e44a913467..a2b5b81d9ba3c 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1661,7 +1661,19 @@ impl Box { where A: 'a, { - unsafe { &mut *Box::into_raw(b) } + unsafe { + let ptr = Box::into_raw(b); + + #[cfg(miri)] + { + extern "Rust" { + fn miri_static_root(ptr: *const u8); + } + miri_static_root(ptr.cast()); + } + + &mut *ptr + } } /// Converts a `Box` into a `Pin>`. If `T` does not implement [`Unpin`], then diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index cd2afd7a47319..4728ca05beeb7 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2842,7 +2842,20 @@ impl Vec { A: 'a, { let mut me = ManuallyDrop::new(self); - unsafe { slice::from_raw_parts_mut(me.as_mut_ptr(), me.len) } + + unsafe { + let ptr = me.as_mut_ptr(); + + #[cfg(miri)] + { + extern "Rust" { + fn miri_static_root(ptr: *const u8); + } + miri_static_root(ptr.cast()); + } + + slice::from_raw_parts_mut(ptr, me.len) + } } /// Returns the remaining spare capacity of the vector as a slice of