Skip to content

Commit 1b3870e

Browse files
committed
remove a dubious example
1 parent eed5df5 commit 1b3870e

File tree

1 file changed

+0
-32
lines changed

1 file changed

+0
-32
lines changed

Diff for: library/core/src/intrinsics.rs

-32
Original file line numberDiff line numberDiff line change
@@ -2583,38 +2583,6 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
25832583
/// }
25842584
/// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
25852585
/// ```
2586-
///
2587-
/// Creating an invalid value:
2588-
///
2589-
/// ```
2590-
/// use std::ptr;
2591-
///
2592-
/// let mut v = Box::new(0i32);
2593-
///
2594-
/// unsafe {
2595-
/// // Leaks the previously held value by overwriting the `Box<T>` with
2596-
/// // a null pointer.
2597-
/// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2598-
/// }
2599-
///
2600-
/// // At this point, using or dropping `v` results in undefined behavior.
2601-
/// // drop(v); // ERROR
2602-
///
2603-
/// // Even leaking `v` "uses" it, and hence is undefined behavior.
2604-
/// // mem::forget(v); // ERROR
2605-
///
2606-
/// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2607-
/// // operation touching it is undefined behavior.
2608-
/// // let v2 = v; // ERROR
2609-
///
2610-
/// unsafe {
2611-
/// // Let us instead put in a valid value
2612-
/// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2613-
/// }
2614-
///
2615-
/// // Now the box is fine
2616-
/// assert_eq!(*v, 42);
2617-
/// ```
26182586
#[doc(alias = "memset")]
26192587
#[stable(feature = "rust1", since = "1.0.0")]
26202588
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]

0 commit comments

Comments
 (0)