Skip to content

Commit cb7d062

Browse files
committed
Auto merge of #26605 - Ms2ger:raw-doc, r=alexcrichton
2 parents 1032384 + 532235b commit cb7d062

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/liballoc/boxed.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<T : ?Sized> Box<T> {
116116
/// of `T` and releases memory. Since the way `Box` allocates and
117117
/// releases memory is unspecified, the only valid pointer to pass
118118
/// to this function is the one taken from another `Box` with
119-
/// `boxed::into_raw` function.
119+
/// `Box::into_raw` function.
120120
///
121121
/// Function is unsafe, because improper use of this function may
122122
/// lead to memory problems like double-free, for example if the
@@ -140,10 +140,8 @@ impl<T : ?Sized> Box<T> {
140140
/// # Examples
141141
/// ```
142142
/// # #![feature(box_raw)]
143-
/// use std::boxed;
144-
///
145143
/// let seventeen = Box::new(17u32);
146-
/// let raw = boxed::into_raw(seventeen);
144+
/// let raw = Box::into_raw(seventeen);
147145
/// let boxed_again = unsafe { Box::from_raw(raw) };
148146
/// ```
149147
#[unstable(feature = "box_raw", reason = "may be renamed")]

src/liballoc/boxed_test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ fn deref() {
7676

7777
#[test]
7878
fn raw_sized() {
79+
let x = Box::new(17);
80+
let p = Box::into_raw(x);
7981
unsafe {
80-
let x = Box::new(17);
81-
let p = boxed::into_raw(x);
8282
assert_eq!(17, *p);
8383
*p = 19;
8484
let y = Box::from_raw(p);
@@ -105,9 +105,9 @@ fn raw_trait() {
105105
}
106106
}
107107

108+
let x: Box<Foo> = Box::new(Bar(17));
109+
let p = Box::into_raw(x);
108110
unsafe {
109-
let x: Box<Foo> = Box::new(Bar(17));
110-
let p = boxed::into_raw(x);
111111
assert_eq!(17, (*p).get());
112112
(*p).set(19);
113113
let y: Box<Foo> = Box::from_raw(p);

src/libcore/ptr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@
5050
//!
5151
//! ```
5252
//! # #![feature(box_raw)]
53-
//! use std::boxed;
53+
//! let my_speed: Box<i32> = Box::new(88);
54+
//! let my_speed: *mut i32 = Box::into_raw(my_speed);
5455
//!
56+
//! // By taking ownership of the original `Box<T>` though
57+
//! // we are obligated to put it together later to be destroyed.
5558
//! unsafe {
56-
//! let my_speed: Box<i32> = Box::new(88);
57-
//! let my_speed: *mut i32 = boxed::into_raw(my_speed);
58-
//!
59-
//! // By taking ownership of the original `Box<T>` though
60-
//! // we are obligated to put it together later to be destroyed.
6159
//! drop(Box::from_raw(my_speed));
6260
//! }
6361
//! ```

0 commit comments

Comments
 (0)