about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-10-27 17:02:42 +0100
committerRalf Jung <post@ralfj.de>2020-10-27 17:02:42 +0100
commitab374dc37c168dbd2125f7322ed2a0e842504bc1 (patch)
tree2206b724bdcb6e7c4bc7b70f0fd8406628c13aad
parent56d288fa46e04cd5faf53d369a1a640a97e2bb08 (diff)
downloadrust-ab374dc37c168dbd2125f7322ed2a0e842504bc1.tar.gz
rust-ab374dc37c168dbd2125f7322ed2a0e842504bc1.zip
fix Box::into_unique
-rw-r--r--library/alloc/src/boxed.rs9
1 files 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<T: ?Sized, A: AllocRef> Box<T, 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
         // 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.