diff options
| author | Ralf Jung <post@ralfj.de> | 2020-10-27 17:02:42 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-10-27 17:02:42 +0100 |
| commit | ab374dc37c168dbd2125f7322ed2a0e842504bc1 (patch) | |
| tree | 2206b724bdcb6e7c4bc7b70f0fd8406628c13aad | |
| parent | 56d288fa46e04cd5faf53d369a1a640a97e2bb08 (diff) | |
| download | rust-ab374dc37c168dbd2125f7322ed2a0e842504bc1.tar.gz rust-ab374dc37c168dbd2125f7322ed2a0e842504bc1.zip | |
fix Box::into_unique
| -rw-r--r-- | library/alloc/src/boxed.rs | 9 |
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. |
