From 04ab4a34719979d7f17b4c0df82ac8dbf08af1ad Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Sun, 24 May 2015 21:45:29 -0400 Subject: Mark `boxed::into_raw` as safe By the same logic that `mem::forget` is safe, `boxed::into_raw` is actually a safe function. Fixes #25755. --- src/liballoc/boxed.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 35732dacd44..6633e48a814 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -139,24 +139,20 @@ impl Box { /// convert pointer back to `Box` with `Box::from_raw` function, because /// `Box` does not specify, how memory is allocated. /// -/// Function is unsafe, because result of this function is no longer -/// automatically managed that may lead to memory or other resource -/// leak. -/// /// # Examples /// ``` /// # #![feature(alloc)] /// use std::boxed; /// /// let seventeen = Box::new(17u32); -/// let raw = unsafe { boxed::into_raw(seventeen) }; +/// let raw = boxed::into_raw(seventeen); /// let boxed_again = unsafe { Box::from_raw(raw) }; /// ``` #[unstable(feature = "alloc", reason = "may be renamed")] #[inline] -pub unsafe fn into_raw(b: Box) -> *mut T { - mem::transmute(b) +pub fn into_raw(b: Box) -> *mut T { + unsafe { mem::transmute(b) } } #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5