From fa67abd12707c34a2def10247c22c336f82cd2c2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 10 Oct 2017 20:55:21 +0300 Subject: rustc: don't special-case Box as having a pointer layout. --- src/liballoc/boxed.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/liballoc/boxed.rs') 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 Place for IntermediateBox { unsafe fn finalize(b: IntermediateBox) -> Box { let p = b.ptr as *mut T; mem::forget(b); - mem::transmute(p) + Box::from_raw(p) } fn make_place() -> IntermediateBox { @@ -300,7 +300,10 @@ impl Box { issue = "27730")] #[inline] pub unsafe fn from_unique(u: Unique) -> 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 Box { issue = "27730")] #[inline] pub fn into_unique(b: Box) -> Unique { - 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 { pub fn downcast(self) -> Result, Box> { >::downcast(self).map_err(|s| unsafe { // reapply the Send marker - mem::transmute::, Box>(s) + Box::from_raw(Box::into_raw(s) as *mut (Any + Send)) }) } } -- cgit 1.4.1-3-g733a5