Skip to content

Commit

Permalink
fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 31, 2018
1 parent b463871 commit 408a6a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ extern "rust-intrinsic" {
/// Creating an invalid value:
///
/// ```
/// use std::{mem, ptr};
/// use std::ptr;
///
/// let mut v = Box::new(0i32);
///
Expand All @@ -1162,8 +1162,10 @@ extern "rust-intrinsic" {
/// // Even leaking `v` "uses" it, and henc eis undefined behavior.
/// // mem::forget(v); // ERROR
///
/// // Let us instead put in a valid value
/// ptr::write(&mut v, Box::new(42i32);
/// unsafe {
/// // Let us instead put in a valid value
/// ptr::write(&mut v, Box::new(42i32));
/// }
///
/// // Now the box is fine
/// assert_eq!(*v, 42);
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ pub use intrinsics::write_bytes;
/// let mut v = vec![Rc::new(0), last];
///
/// unsafe {
/// // Get a raw pointer to the last element in `v`.
/// let ptr = &mut v[1] as *mut _;
/// // Shorten `v` to prevent the last item from being dropped. We do that first,
/// // to prevent issues if the `drop_in_place` below panics.
/// v.set_len(1);
/// // Without a call `drop_in_place`, the last item would never be dropped,
/// // and the memory it manages would be leaked.
/// ptr::drop_in_place(&mut v[1]);
/// ptr::drop_in_place(ptr);
/// }
///
/// assert_eq!(v, &[0.into()]);
Expand Down

0 comments on commit 408a6a0

Please sign in to comment.