about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2017-10-10 20:55:21 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2017-11-19 02:43:55 +0200
commitfa67abd12707c34a2def10247c22c336f82cd2c2 (patch)
tree64e70b9c296d09188d5628de3860cf9df4c94755 /src/liballoc
parent18ecc564f2cee4da3ef9397ba58e19d3fd9be3de (diff)
downloadrust-fa67abd12707c34a2def10247c22c336f82cd2c2.tar.gz
rust-fa67abd12707c34a2def10247c22c336f82cd2c2.zip
rustc: don't special-case Box<T> as having a pointer layout.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 79292d390e5..2226cee6e36 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -151,7 +151,7 @@ impl<T> Place<T> for IntermediateBox<T> {
 unsafe fn finalize<T>(b: IntermediateBox<T>) -> Box<T> {
     let p = b.ptr as *mut T;
     mem::forget(b);
-    mem::transmute(p)
+    Box::from_raw(p)
 }
 
 fn make_place<T>() -> IntermediateBox<T> {
@@ -300,7 +300,10 @@ impl<T: ?Sized> Box<T> {
                issue = "27730")]
     #[inline]
     pub unsafe fn from_unique(u: Unique<T>) -> Self {
-        mem::transmute(u)
+        #[cfg(stage0)]
+        return mem::transmute(u);
+        #[cfg(not(stage0))]
+        return Box(u);
     }
 
     /// Consumes the `Box`, returning the wrapped raw pointer.
@@ -362,7 +365,14 @@ impl<T: ?Sized> Box<T> {
                issue = "27730")]
     #[inline]
     pub fn into_unique(b: Box<T>) -> Unique<T> {
-        unsafe { mem::transmute(b) }
+        #[cfg(stage0)]
+        return unsafe { mem::transmute(b) };
+        #[cfg(not(stage0))]
+        return {
+            let unique = b.0;
+            mem::forget(b);
+            unique
+        };
     }
 }
 
@@ -627,7 +637,7 @@ impl Box<Any + Send> {
     pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
         <Box<Any>>::downcast(self).map_err(|s| unsafe {
             // reapply the Send marker
-            mem::transmute::<Box<Any>, Box<Any + Send>>(s)
+            Box::from_raw(Box::into_raw(s) as *mut (Any + Send))
         })
     }
 }