Skip to content

Commit edb2c2d

Browse files
committed
Remove uses of mem::transmute in Box methods
Makes use of conversions via Unique.
1 parent 1c4510a commit edb2c2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/liballoc/boxed.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<T: ?Sized> Box<T> {
269269
#[stable(feature = "box_raw", since = "1.4.0")]
270270
#[inline]
271271
pub unsafe fn from_raw(raw: *mut T) -> Self {
272-
mem::transmute(raw)
272+
Box(Unique::new_unchecked(raw))
273273
}
274274

275275
/// Consumes the `Box`, returning the wrapped raw pointer.
@@ -295,7 +295,7 @@ impl<T: ?Sized> Box<T> {
295295
#[stable(feature = "box_raw", since = "1.4.0")]
296296
#[inline]
297297
pub fn into_raw(b: Box<T>) -> *mut T {
298-
unsafe { mem::transmute(b) }
298+
Box::into_unique(b).as_ptr()
299299
}
300300

301301
/// Consumes the `Box`, returning the wrapped pointer as `Unique<T>`.
@@ -326,7 +326,9 @@ impl<T: ?Sized> Box<T> {
326326
issue = "27730")]
327327
#[inline]
328328
pub fn into_unique(b: Box<T>) -> Unique<T> {
329-
unsafe { mem::transmute(b) }
329+
let u = b.0;
330+
mem::forget(b);
331+
u
330332
}
331333
}
332334

0 commit comments

Comments
 (0)