diff options
| author | Ralf Jung <post@ralfj.de> | 2019-02-13 16:26:13 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2019-02-13 17:26:08 +0100 |
| commit | 719be246ae708508a19436a0b8ee1be29882e21e (patch) | |
| tree | 400694dffc69d9225d4d3da525b4cee2263a3a35 /src/liballoc | |
| parent | e54494727855cd14229f5d456591ed2a2f027c46 (diff) | |
| download | rust-719be246ae708508a19436a0b8ee1be29882e21e.tar.gz rust-719be246ae708508a19436a0b8ee1be29882e21e.zip | |
fix Box::into_unique effecitvely transmuting to a raw ptr
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8e01e12e0b8..f6411a3db87 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -202,10 +202,15 @@ impl<T: ?Sized> Box<T> { #[unstable(feature = "ptr_internals", issue = "0", reason = "use into_raw_non_null instead")] #[inline] #[doc(hidden)] - pub fn into_unique(b: Box<T>) -> Unique<T> { - let unique = b.0; + pub fn into_unique(mut b: Box<T>) -> Unique<T> { + // Box is kind-of a library type, but recognized as a "unique pointer" by + // Stacked Borrows. This function here corresponds to "reborrowing to + // a raw pointer", but there is no actual reborrow here -- so + // without some care, the pointer we are returning here still carries + // the `Uniq` tag. We round-trip through a mutable reference to avoid that. + let unique = unsafe { b.0.as_mut() as *mut T }; mem::forget(b); - unique + unsafe { Unique::new_unchecked(unique) } } /// Consumes and leaks the `Box`, returning a mutable reference, |
