Skip to content

fix Box::into_unique #78446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down