about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-05-19 13:54:23 +0200
committerAmanieu d'Antras <amanieu@gmail.com>2025-07-01 19:54:38 +0200
commit8797d54812393baeff99ffe257fa056c3dfdb656 (patch)
tree85aa954a430d997f5780208a176c611313acc0af /library/alloc/src
parent15bd619d5f12b4d01bb645340e7eea97d7b0e7c7 (diff)
downloadrust-8797d54812393baeff99ffe257fa056c3dfdb656.tar.gz
rust-8797d54812393baeff99ffe257fa056c3dfdb656.zip
make Box::into_raw compatible with Stacked Borrows again
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/boxed.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index c84799bc83c..4e3f76de49e 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -1150,8 +1150,11 @@ impl<T: ?Sized> Box<T> {
     #[stable(feature = "box_raw", since = "1.4.0")]
     #[inline]
     pub fn into_raw(b: Self) -> *mut T {
-        // Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
-        unsafe { &raw mut *&mut *Self::into_raw_with_allocator(b).0 }
+        // Avoid `into_raw_with_allocator` as that interacts poorly with Miri's Stacked Borrows.
+        let mut b = mem::ManuallyDrop::new(b);
+        // We go through the built-in deref for `Box`, which is crucial for Miri to recognize this
+        // operation for it's alias tracking.
+        &raw mut **b
     }
 
     /// Consumes the `Box`, returning a wrapped `NonNull` pointer.