From ab374dc37c168dbd2125f7322ed2a0e842504bc1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 27 Oct 2020 17:02:42 +0100 Subject: [PATCH] fix Box::into_unique --- library/alloc/src/boxed.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 997dd975c83..1512235da6a 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -724,15 +724,10 @@ impl Box { // 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 // 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. - 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) }; - (ptr, alloc) + (Unique::from(Box::leak(b)), alloc) } /// Returns a reference to the underlying allocator.