]> git.lizzy.rs Git - rust.git/commitdiff
Remove uses of mem::transmute in Box methods
authorNikolai Vazquez <nvazquez1297@gmail.com>
Wed, 27 Sep 2017 01:16:59 +0000 (21:16 -0400)
committerNikolai Vazquez <nvazquez1297@gmail.com>
Wed, 27 Sep 2017 01:16:59 +0000 (21:16 -0400)
Makes use of conversions via Unique.

src/liballoc/boxed.rs

index 4341b0b2975beeb9fccf93bb750153a929d61403..512c7194fe3ff3340645db1dcd06da7bbb1657e6 100644 (file)
@@ -269,7 +269,7 @@ impl<T: ?Sized> Box<T> {
     #[stable(feature = "box_raw", since = "1.4.0")]
     #[inline]
     pub unsafe fn from_raw(raw: *mut T) -> Self {
-        mem::transmute(raw)
+        Box(Unique::new_unchecked(raw))
     }
 
     /// Consumes the `Box`, returning the wrapped raw pointer.
@@ -295,7 +295,7 @@ pub unsafe fn from_raw(raw: *mut T) -> Self {
     #[stable(feature = "box_raw", since = "1.4.0")]
     #[inline]
     pub fn into_raw(b: Box<T>) -> *mut T {
-        unsafe { mem::transmute(b) }
+        Box::into_unique(b).as_ptr()
     }
 
     /// Consumes the `Box`, returning the wrapped pointer as `Unique<T>`.
@@ -326,7 +326,9 @@ pub fn into_raw(b: Box<T>) -> *mut T {
                issue = "27730")]
     #[inline]
     pub fn into_unique(b: Box<T>) -> Unique<T> {
-        unsafe { mem::transmute(b) }
+        let u = b.0;
+        mem::forget(b);
+        u
     }
 }