@@ -11,123 +11,3 @@ index 04033905728..ef37fef0455 100644
11
11
/// // In general .write is required to avoid attempting to destruct
12
12
/// // the (uninitialized) previous contents of `ptr`, though for this
13
13
/// // simple example `*ptr = 5` would have worked as well.
14
- diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
15
- index 64342de6341..4d7d47579ee 100644
16
- --- a/library/core/src/mem/maybe_uninit.rs
17
- +++ b/library/core/src/mem/maybe_uninit.rs
18
- @@ -736,22 +736,22 @@ pub unsafe fn assume_init_drop(&mut self) {
19
- /// #![feature(maybe_uninit_ref)]
20
- /// use std::mem::MaybeUninit;
21
- ///
22
- - /// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 2048]) { *buf = [0; 2048] }
23
- + /// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { *buf = [0; 1024] }
24
- /// # #[cfg(FALSE)]
25
- /// extern "C" {
26
- /// /// Initializes *all* the bytes of the input buffer.
27
- - /// fn initialize_buffer(buf: *mut [u8; 2048]);
28
- + /// fn initialize_buffer(buf: *mut [u8; 1024]);
29
- /// }
30
- ///
31
- - /// let mut buf = MaybeUninit::<[u8; 2048]>::uninit();
32
- + /// let mut buf = MaybeUninit::<[u8; 1024]>::uninit();
33
- ///
34
- /// // Initialize `buf`:
35
- /// unsafe { initialize_buffer(buf.as_mut_ptr()); }
36
- /// // Now we know that `buf` has been initialized, so we could `.assume_init()` it.
37
- - /// // However, using `.assume_init()` may trigger a `memcpy` of the 2048 bytes.
38
- + /// // However, using `.assume_init()` may trigger a `memcpy` of the 1024 bytes.
39
- /// // To assert our buffer has been initialized without copying it, we upgrade
40
- - /// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
41
- - /// let buf: &mut [u8; 2048] = unsafe {
42
- + /// // the `&mut MaybeUninit<[u8; 1024]>` to a `&mut [u8; 1024]`:
43
- + /// let buf: &mut [u8; 1024] = unsafe {
44
- /// // SAFETY: `buf` has been initialized.
45
- /// buf.assume_init_mut()
46
- /// };
47
- diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
48
- index f18387d020d..4571ba154ea 100644
49
- --- a/library/core/src/ptr/const_ptr.rs
50
- +++ b/library/core/src/ptr/const_ptr.rs
51
- @@ -724,7 +724,7 @@ pub const fn wrapping_sub(self, count: usize) -> Self
52
- /// #![feature(set_ptr_value)]
53
- /// # use core::fmt::Debug;
54
- /// let arr: [i32; 3] = [1, 2, 3];
55
- - /// let mut ptr = &arr[0] as *const dyn Debug;
56
- + /// let mut ptr = arr.as_ptr() as *const dyn Debug;
57
- /// let thin = ptr as *const u8;
58
- /// unsafe {
59
- /// ptr = ptr.set_ptr_value(thin.add(8));
60
- diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
61
- index 3c6f1978283..ba08823e343 100644
62
- --- a/library/core/src/ptr/mut_ptr.rs
63
- +++ b/library/core/src/ptr/mut_ptr.rs
64
- @@ -830,7 +830,7 @@ pub const fn wrapping_sub(self, count: usize) -> Self
65
- /// #![feature(set_ptr_value)]
66
- /// # use core::fmt::Debug;
67
- /// let mut arr: [i32; 3] = [1, 2, 3];
68
- - /// let mut ptr = &mut arr[0] as *mut dyn Debug;
69
- + /// let mut ptr = arr.as_mut_ptr() as *mut dyn Debug;
70
- /// let thin = ptr as *mut u8;
71
- /// unsafe {
72
- /// ptr = ptr.set_ptr_value(thin.add(8));
73
- diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
74
- index bf70b28579c..9085d5c7b97 100644
75
- --- a/library/core/src/sync/atomic.rs
76
- +++ b/library/core/src/sync/atomic.rs
77
- @@ -78,7 +78,7 @@
78
- //! ```
79
- //! use std::sync::Arc;
80
- //! use std::sync::atomic::{AtomicUsize, Ordering};
81
- - //! use std::thread;
82
- + //! use std::{hint, thread};
83
- //!
84
- //! fn main() {
85
- //! let spinlock = Arc::new(AtomicUsize::new(1));
86
- @@ -89,7 +89,9 @@
87
- //! });
88
- //!
89
- //! // Wait for the other thread to release the lock
90
- - //! while spinlock.load(Ordering::SeqCst) != 0 {}
91
- + //! while spinlock.load(Ordering::SeqCst) != 0 {
92
- + //! hint::spin_loop();
93
- + //! }
94
- //!
95
- //! if let Err(panic) = thread.join() {
96
- //! println!("Thread had an error: {:?}", panic);
97
- @@ -898,8 +900,10 @@ pub const fn new(p: *mut T) -> AtomicPtr<T> {
98
- /// ```
99
- /// use std::sync::atomic::{AtomicPtr, Ordering};
100
- ///
101
- - /// let mut atomic_ptr = AtomicPtr::new(&mut 10);
102
- - /// *atomic_ptr.get_mut() = &mut 5;
103
- + /// let mut data = 10;
104
- + /// let mut atomic_ptr = AtomicPtr::new(&mut data);
105
- + /// let mut other_data = 5;
106
- + /// *atomic_ptr.get_mut() = &mut other_data;
107
- /// assert_eq!(unsafe { *atomic_ptr.load(Ordering::SeqCst) }, 5);
108
- /// ```
109
- #[inline]
110
- @@ -916,9 +920,11 @@ pub fn get_mut(&mut self) -> &mut *mut T {
111
- /// #![feature(atomic_from_mut)]
112
- /// use std::sync::atomic::{AtomicPtr, Ordering};
113
- ///
114
- - /// let mut some_ptr = &mut 123 as *mut i32;
115
- + /// let mut data = 123;
116
- + /// let mut some_ptr = &mut data as *mut i32;
117
- /// let a = AtomicPtr::from_mut(&mut some_ptr);
118
- - /// a.store(&mut 456, Ordering::Relaxed);
119
- + /// let mut other_data = 456;
120
- + /// a.store(&mut other_data, Ordering::Relaxed);
121
- /// assert_eq!(unsafe { *some_ptr }, 456);
122
- /// ```
123
- #[inline]
124
- @@ -944,7 +950,8 @@ pub fn from_mut(v: &mut *mut T) -> &Self {
125
- /// ```
126
- /// use std::sync::atomic::AtomicPtr;
127
- ///
128
- - /// let atomic_ptr = AtomicPtr::new(&mut 5);
129
- + /// let mut data = 5;
130
- + /// let atomic_ptr = AtomicPtr::new(&mut data);
131
- /// assert_eq!(unsafe { *atomic_ptr.into_inner() }, 5);
132
- /// ```
133
- #[inline]
0 commit comments