Skip to content

Commit ab374dc

Browse files
committed
fix Box::into_unique
1 parent 56d288f commit ab374dc

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)