Skip to content

Commit 79f62cb

Browse files
committed
Box::leak - fixed bug in documentation
1 parent 2b48b47 commit 79f62cb

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/liballoc/boxed.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,27 @@ impl<T: ?Sized> Box<T> {
386386
/// Simple usage:
387387
///
388388
/// ```
389-
/// let x = Box::new(41);
390-
/// let static_ref = Box::leak(x);
391-
/// *static_ref += 1;
392-
/// assert_eq!(*static_ref, 42);
389+
/// #![feature(box_leak)]
390+
///
391+
/// fn main() {
392+
/// let x = Box::new(41);
393+
/// let static_ref = Box::leak(x);
394+
/// *static_ref += 1;
395+
/// assert_eq!(*static_ref, 42);
396+
/// }
393397
/// ```
394398
///
395399
/// Unsized data:
396400
///
397401
/// ```
398-
/// let x = vec![1, 2, 3].into_boxed_slice();
399-
/// let static_ref = Box::leak(x);
400-
/// static_ref[0] = 4;
401-
/// assert_eq!(*static_ref, [4, 2, 3]);
402+
/// #![feature(box_leak)]
403+
///
404+
/// fn main() {
405+
/// let x = vec![1, 2, 3].into_boxed_slice();
406+
/// let static_ref = Box::leak(x);
407+
/// static_ref[0] = 4;
408+
/// assert_eq!(*static_ref, [4, 2, 3]);
409+
/// }
402410
/// ```
403411
#[unstable(feature = "box_leak", reason = "needs an FCP to stabilize",
404412
issue = "0")]

0 commit comments

Comments
 (0)