Skip to content

Commit a53fb30

Browse files
committed
Auto merge of rust-lang#78446 - RalfJung:box, r=Amanieu
fix Box::into_unique rust-lang#77187 broke Stacked Borrows pointer tagging around `Box::into_unique` (this is caused by `Box` being a special case in the type system, which box-internal code needs to account for). This PR fixes that. r? `@Amanieu` Cc `@TimDiekmann` Fixes rust-lang#78419.
2 parents ae9731c + ab374dc commit a53fb30

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

library/alloc/src/boxed.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,10 @@ impl<T: ?Sized, A: AllocRef> Box<T, A> {
724724
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
725725
// raw pointer for the type system. Turning it directly into a raw pointer would not be
726726
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
727-
// so all raw pointer methods have to leak the box. Turning *that* to a raw pointer
727+
// so all raw pointer methods have to go through `Box::leak`. Turning *that* to a raw pointer
728728
// behaves correctly.
729-
let b = mem::ManuallyDrop::new(b);
730-
731-
// The box is unitiliazed later when moving out the allocator. The pointer is stored
732-
// beforehand.
733-
let ptr = b.0;
734729
let alloc = unsafe { ptr::read(&b.1) };
735-
(ptr, alloc)
730+
(Unique::from(Box::leak(b)), alloc)
736731
}
737732

738733
/// Returns a reference to the underlying allocator.

0 commit comments

Comments
 (0)