about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-07-11 11:36:08 -0400
committerRalf Jung <post@ralfj.de>2022-07-11 11:36:18 -0400
commit1b3870e4271ca7b93de0b17ea6544e749fba3483 (patch)
tree177e10d3cff5f599c8c94c53527533b88d7bb986
parenteed5df52f63dbf19030fb99045334252fcd5b366 (diff)
downloadrust-1b3870e4271ca7b93de0b17ea6544e749fba3483.tar.gz
rust-1b3870e4271ca7b93de0b17ea6544e749fba3483.zip
remove a dubious example
-rw-r--r--library/core/src/intrinsics.rs32
1 files changed, 0 insertions, 32 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 5f40a59f0b8..a9330a86920 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -2583,38 +2583,6 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
 /// }
 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
 /// ```
-///
-/// Creating an invalid value:
-///
-/// ```
-/// use std::ptr;
-///
-/// let mut v = Box::new(0i32);
-///
-/// unsafe {
-///     // Leaks the previously held value by overwriting the `Box<T>` with
-///     // a null pointer.
-///     ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
-/// }
-///
-/// // At this point, using or dropping `v` results in undefined behavior.
-/// // drop(v); // ERROR
-///
-/// // Even leaking `v` "uses" it, and hence is undefined behavior.
-/// // mem::forget(v); // ERROR
-///
-/// // In fact, `v` is invalid according to basic type layout invariants, so *any*
-/// // operation touching it is undefined behavior.
-/// // let v2 = v; // ERROR
-///
-/// unsafe {
-///     // Let us instead put in a valid value
-///     ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
-/// }
-///
-/// // Now the box is fine
-/// assert_eq!(*v, 42);
-/// ```
 #[doc(alias = "memset")]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]