Skip to content

Commit 7cb9914

Browse files
committed
Auto merge of #25767 - mystor:patch-1, r=Gankro
By the same logic that `mem::forget` is safe, `boxed::into_raw` is actually a safe function. Fixes #25755.
2 parents cc156c2 + d416fc1 commit 7cb9914

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/liballoc/boxed.rs

+3-7
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")]

src/libstd/sync/mpsc/spsc_queue.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ unsafe impl<T: Send> Sync for Queue<T> { }
8080

8181
impl<T> Node<T> {
8282
fn new() -> *mut Node<T> {
83-
unsafe {
84-
boxed::into_raw(box Node {
85-
value: None,
86-
next: AtomicPtr::new(ptr::null_mut::<Node<T>>()),
87-
})
88-
}
83+
boxed::into_raw(box Node {
84+
value: None,
85+
next: AtomicPtr::new(ptr::null_mut::<Node<T>>()),
86+
})
8987
}
9088
}
9189

0 commit comments

Comments
 (0)