Skip to content

Commit 04ab4a3

Browse files
committed
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.
1 parent 893e416 commit 04ab4a3

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/liballoc/boxed.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,20 @@ impl<T : ?Sized> Box<T> {
139139
/// convert pointer back to `Box` with `Box::from_raw` function, because
140140
/// `Box` does not specify, how memory is allocated.
141141
///
142-
/// Function is unsafe, because result of this function is no longer
143-
/// automatically managed that may lead to memory or other resource
144-
/// leak.
145-
///
146142
/// # Examples
147143
/// ```
148144
/// # #![feature(alloc)]
149145
/// use std::boxed;
150146
///
151147
/// let seventeen = Box::new(17u32);
152-
/// let raw = unsafe { boxed::into_raw(seventeen) };
148+
/// let raw = boxed::into_raw(seventeen);
153149
/// let boxed_again = unsafe { Box::from_raw(raw) };
154150
/// ```
155151
#[unstable(feature = "alloc",
156152
reason = "may be renamed")]
157153
#[inline]
158-
pub unsafe fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {
159-
mem::transmute(b)
154+
pub fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {
155+
unsafe { mem::transmute(b) }
160156
}
161157

162158
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)