fix Box::into_unique

This commit is contained in:
Ralf Jung 2020-10-27 17:02:42 +01:00
parent 56d288fa46
commit ab374dc37c

View File

@ -724,15 +724,10 @@ pub fn into_unique(b: Self) -> (Unique<T>, A) {
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a // Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
// raw pointer for the type system. Turning it directly into a raw pointer would not be // raw pointer for the type system. Turning it directly into a raw pointer would not be
// recognized as "releasing" the unique pointer to permit aliased raw accesses, // recognized as "releasing" the unique pointer to permit aliased raw accesses,
// so all raw pointer methods have to leak the box. Turning *that* to a raw pointer // so all raw pointer methods have to go through `Box::leak`. Turning *that* to a raw pointer
// behaves correctly. // behaves correctly.
let b = mem::ManuallyDrop::new(b);
// The box is unitiliazed later when moving out the allocator. The pointer is stored
// beforehand.
let ptr = b.0;
let alloc = unsafe { ptr::read(&b.1) }; let alloc = unsafe { ptr::read(&b.1) };
(ptr, alloc) (Unique::from(Box::leak(b)), alloc)
} }
/// Returns a reference to the underlying allocator. /// Returns a reference to the underlying allocator.