Skip to content

Commit e3c5921

Browse files
committed
make Box::into_raw compatible with Stacked Borrows again
1 parent ac178fc commit e3c5921

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/alloc/src/boxed.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,9 @@ impl<T: ?Sized> Box<T> {
11501150
#[stable(feature = "box_raw", since = "1.4.0")]
11511151
#[inline]
11521152
pub fn into_raw(b: Self) -> *mut T {
1153-
// Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
1154-
unsafe { &raw mut *&mut *Self::into_raw_with_allocator(b).0 }
1153+
// Avoid `into_raw_with_allocator` as that interacts poorly with Miri's Stacked Borrows.
1154+
let mut b = mem::ManuallyDrop::new(b);
1155+
&raw mut **b
11551156
}
11561157

11571158
/// Consumes the `Box`, returning a wrapped `NonNull` pointer.

0 commit comments

Comments
 (0)