Skip to content

Commit a14efd1

Browse files
committed
Rename MaybeUninit::read to assume_init_read.
1 parent 656a17b commit a14efd1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

library/core/src/array/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
103103
// dead now (i.e. do not touch). As `idx` was the start of the
104104
// alive-zone, the alive zone is now `data[alive]` again, restoring
105105
// all invariants.
106-
unsafe { self.data.get_unchecked(idx).read() }
106+
unsafe { self.data.get_unchecked(idx).assume_init_read() }
107107
})
108108
}
109109

@@ -136,7 +136,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
136136
// dead now (i.e. do not touch). As `idx` was the end of the
137137
// alive-zone, the alive zone is now `data[alive]` again, restoring
138138
// all invariants.
139-
unsafe { self.data.get_unchecked(idx).read() }
139+
unsafe { self.data.get_unchecked(idx).assume_init_read() }
140140
})
141141
}
142142
}

library/core/src/mem/maybe_uninit.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ impl<T> MaybeUninit<T> {
520520
/// this initialization invariant.
521521
///
522522
/// Moreover, this leaves a copy of the same data behind in the `MaybeUninit<T>`. When using
523-
/// multiple copies of the data (by calling `read` multiple times, or first
524-
/// calling `read` and then [`assume_init`]), it is your responsibility
523+
/// multiple copies of the data (by calling `assume_init_read` multiple times, or first
524+
/// calling `assume_init_read` and then [`assume_init`]), it is your responsibility
525525
/// to ensure that that data may indeed be duplicated.
526526
///
527527
/// [inv]: #initialization-invariant
@@ -537,16 +537,16 @@ impl<T> MaybeUninit<T> {
537537
///
538538
/// let mut x = MaybeUninit::<u32>::uninit();
539539
/// x.write(13);
540-
/// let x1 = unsafe { x.read() };
540+
/// let x1 = unsafe { x.assume_init_read() };
541541
/// // `u32` is `Copy`, so we may read multiple times.
542-
/// let x2 = unsafe { x.read() };
542+
/// let x2 = unsafe { x.assume_init_read() };
543543
/// assert_eq!(x1, x2);
544544
///
545545
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
546546
/// x.write(None);
547-
/// let x1 = unsafe { x.read() };
547+
/// let x1 = unsafe { x.assume_init_read() };
548548
/// // Duplicating a `None` value is okay, so we may read multiple times.
549-
/// let x2 = unsafe { x.read() };
549+
/// let x2 = unsafe { x.assume_init_read() };
550550
/// assert_eq!(x1, x2);
551551
/// ```
552552
///
@@ -558,14 +558,14 @@ impl<T> MaybeUninit<T> {
558558
///
559559
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
560560
/// x.write(Some(vec![0,1,2]));
561-
/// let x1 = unsafe { x.read() };
562-
/// let x2 = unsafe { x.read() };
561+
/// let x1 = unsafe { x.assume_init_read() };
562+
/// let x2 = unsafe { x.assume_init_read() };
563563
/// // We now created two copies of the same vector, leading to a double-free ⚠️ when
564564
/// // they both get dropped!
565565
/// ```
566566
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
567567
#[inline(always)]
568-
pub unsafe fn read(&self) -> T {
568+
pub unsafe fn assume_init_read(&self) -> T {
569569
// SAFETY: the caller must guarantee that `self` is initialized.
570570
// Reading from `self.as_ptr()` is safe since `self` should be initialized.
571571
unsafe {

0 commit comments

Comments
 (0)