about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-08-31 18:25:42 +0200
committerRalf Jung <post@ralfj.de>2018-08-31 18:47:41 +0200
commit408a6a00c228bbc762aa34f96a003703019c9e8d (patch)
treeb604dfb2abfdea585bf85a42c93d3f49e68eb3e8
parentb463871df555984fddf1d4cb59d12119a28e98df (diff)
downloadrust-408a6a00c228bbc762aa34f96a003703019c9e8d.tar.gz
rust-408a6a00c228bbc762aa34f96a003703019c9e8d.zip
fix doctests
-rw-r--r--src/libcore/intrinsics.rs8
-rw-r--r--src/libcore/ptr.rs4
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()]);