Skip to content

Commit 3c0a034

Browse files
committed
Fix doc-tests for Box
1 parent e04bcd9 commit 3c0a034

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/liballoc/boxed.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,11 @@ impl<T, A: AllocRef> Box<T, A> {
267267
///
268268
/// ```
269269
/// #![feature(allocator_api)]
270+
/// #![feature(new_uninit)]
270271
///
271272
/// use std::alloc::System;
272273
///
273-
/// let mut five = Box::<u32>::new_uninit_in(System);
274+
/// let mut five = Box::<u32, _>::new_uninit_in(System);
274275
///
275276
/// let five = unsafe {
276277
/// // Deferred initialization:
@@ -302,10 +303,11 @@ impl<T, A: AllocRef> Box<T, A> {
302303
///
303304
/// ```
304305
/// #![feature(allocator_api)]
306+
/// #![feature(new_uninit)]
305307
///
306308
/// use std::alloc::System;
307309
///
308-
/// let zero = Box::<u32>::new_zeroed_in(System);
310+
/// let zero = Box::<u32, _>::new_zeroed_in(System);
309311
/// let zero = unsafe { zero.assume_init() };
310312
///
311313
/// assert_eq!(*zero, 0)
@@ -520,13 +522,16 @@ impl<T: ?Sized, A: AllocRef> Box<T, A> {
520522
/// ```
521523
/// Manually create a `Box` from scratch by using the global allocator:
522524
/// ```
523-
/// use std::alloc::{alloc, Layout, AllocRef, AllocInit};
525+
/// #![feature(allocator_api)]
526+
///
527+
/// use std::alloc::{Layout, AllocRef, AllocInit, System};
524528
///
525529
/// unsafe {
526-
/// let ptr = System.alloc(Layout::new::<i32>(), AllocInit::Uninitialized) as *mut i32;
530+
/// let ptr = System.alloc(Layout::new::<i32>(), AllocInit::Uninitialized)?.ptr.as_ptr();
527531
/// *ptr = 5;
528532
/// let x = Box::from_raw_in(ptr, System);
529533
/// }
534+
/// # Ok::<_, std::alloc::AllocErr>(())
530535
/// ```
531536
///
532537
/// [memory layout]: index.html#memory-layout

0 commit comments

Comments
 (0)