about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-29 12:08:16 +0000
committerbors <bors@rust-lang.org>2020-10-29 12:08:16 +0000
commita53fb30e3bf2655b0563da6d561c23cda5f3ec11 (patch)
treea8eccb71012840fc28f743581429533c2ccb97f0
parentae9731ce1db8afa4794110f1b4780b9128a5cae8 (diff)
parentab374dc37c168dbd2125f7322ed2a0e842504bc1 (diff)
downloadrust-a53fb30e3bf2655b0563da6d561c23cda5f3ec11.tar.gz
rust-a53fb30e3bf2655b0563da6d561c23cda5f3ec11.zip
Auto merge of #78446 - RalfJung:box, r=Amanieu
fix Box::into_unique

https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/78419.
-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.