Skip to content

Commit 408a6a0

Browse files
committed
fix doctests
1 parent b463871 commit 408a6a0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/libcore/intrinsics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ extern "rust-intrinsic" {
11461146
/// Creating an invalid value:
11471147
///
11481148
/// ```
1149-
/// use std::{mem, ptr};
1149+
/// use std::ptr;
11501150
///
11511151
/// let mut v = Box::new(0i32);
11521152
///
@@ -1162,8 +1162,10 @@ extern "rust-intrinsic" {
11621162
/// // Even leaking `v` "uses" it, and henc eis undefined behavior.
11631163
/// // mem::forget(v); // ERROR
11641164
///
1165-
/// // Let us instead put in a valid value
1166-
/// ptr::write(&mut v, Box::new(42i32);
1165+
/// unsafe {
1166+
/// // Let us instead put in a valid value
1167+
/// ptr::write(&mut v, Box::new(42i32));
1168+
/// }
11671169
///
11681170
/// // Now the box is fine
11691171
/// assert_eq!(*v, 42);

src/libcore/ptr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,14 @@ pub use intrinsics::write_bytes;
136136
/// let mut v = vec![Rc::new(0), last];
137137
///
138138
/// unsafe {
139+
/// // Get a raw pointer to the last element in `v`.
140+
/// let ptr = &mut v[1] as *mut _;
139141
/// // Shorten `v` to prevent the last item from being dropped. We do that first,
140142
/// // to prevent issues if the `drop_in_place` below panics.
141143
/// v.set_len(1);
142144
/// // Without a call `drop_in_place`, the last item would never be dropped,
143145
/// // and the memory it manages would be leaked.
144-
/// ptr::drop_in_place(&mut v[1]);
146+
/// ptr::drop_in_place(ptr);
145147
/// }
146148
///
147149
/// assert_eq!(v, &[0.into()]);

0 commit comments

Comments
 (0)