diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-31 18:25:42 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-31 18:47:41 +0200 |
| commit | 408a6a00c228bbc762aa34f96a003703019c9e8d (patch) | |
| tree | b604dfb2abfdea585bf85a42c93d3f49e68eb3e8 | |
| parent | b463871df555984fddf1d4cb59d12119a28e98df (diff) | |
| download | rust-408a6a00c228bbc762aa34f96a003703019c9e8d.tar.gz rust-408a6a00c228bbc762aa34f96a003703019c9e8d.zip | |
fix doctests
| -rw-r--r-- | src/libcore/intrinsics.rs | 8 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 927c6f26b62..659b7a23ed9 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1146,7 +1146,7 @@ extern "rust-intrinsic" { /// Creating an invalid value: /// /// ``` - /// use std::{mem, ptr}; + /// use std::ptr; /// /// let mut v = Box::new(0i32); /// @@ -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); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index adf107dca22..dba8513d5f0 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -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()]); |
