Rename MaybeUninit::read to assume_init_read.
This commit is contained in:
parent
656a17b44d
commit
a14efd1d0a
|
@ -103,7 +103,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
|
|||
// dead now (i.e. do not touch). As `idx` was the start of the
|
||||
// alive-zone, the alive zone is now `data[alive]` again, restoring
|
||||
// all invariants.
|
||||
unsafe { self.data.get_unchecked(idx).read() }
|
||||
unsafe { self.data.get_unchecked(idx).assume_init_read() }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
|
|||
// dead now (i.e. do not touch). As `idx` was the end of the
|
||||
// alive-zone, the alive zone is now `data[alive]` again, restoring
|
||||
// all invariants.
|
||||
unsafe { self.data.get_unchecked(idx).read() }
|
||||
unsafe { self.data.get_unchecked(idx).assume_init_read() }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,8 +520,8 @@ impl<T> MaybeUninit<T> {
|
|||
/// this initialization invariant.
|
||||
///
|
||||
/// Moreover, this leaves a copy of the same data behind in the `MaybeUninit<T>`. When using
|
||||
/// multiple copies of the data (by calling `read` multiple times, or first
|
||||
/// calling `read` and then [`assume_init`]), it is your responsibility
|
||||
/// multiple copies of the data (by calling `assume_init_read` multiple times, or first
|
||||
/// calling `assume_init_read` and then [`assume_init`]), it is your responsibility
|
||||
/// to ensure that that data may indeed be duplicated.
|
||||
///
|
||||
/// [inv]: #initialization-invariant
|
||||
|
@ -537,16 +537,16 @@ impl<T> MaybeUninit<T> {
|
|||
///
|
||||
/// let mut x = MaybeUninit::<u32>::uninit();
|
||||
/// x.write(13);
|
||||
/// let x1 = unsafe { x.read() };
|
||||
/// let x1 = unsafe { x.assume_init_read() };
|
||||
/// // `u32` is `Copy`, so we may read multiple times.
|
||||
/// let x2 = unsafe { x.read() };
|
||||
/// let x2 = unsafe { x.assume_init_read() };
|
||||
/// assert_eq!(x1, x2);
|
||||
///
|
||||
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
|
||||
/// x.write(None);
|
||||
/// let x1 = unsafe { x.read() };
|
||||
/// let x1 = unsafe { x.assume_init_read() };
|
||||
/// // Duplicating a `None` value is okay, so we may read multiple times.
|
||||
/// let x2 = unsafe { x.read() };
|
||||
/// let x2 = unsafe { x.assume_init_read() };
|
||||
/// assert_eq!(x1, x2);
|
||||
/// ```
|
||||
///
|
||||
|
@ -558,14 +558,14 @@ impl<T> MaybeUninit<T> {
|
|||
///
|
||||
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
|
||||
/// x.write(Some(vec![0,1,2]));
|
||||
/// let x1 = unsafe { x.read() };
|
||||
/// let x2 = unsafe { x.read() };
|
||||
/// let x1 = unsafe { x.assume_init_read() };
|
||||
/// let x2 = unsafe { x.assume_init_read() };
|
||||
/// // We now created two copies of the same vector, leading to a double-free ⚠️ when
|
||||
/// // they both get dropped!
|
||||
/// ```
|
||||
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
|
||||
#[inline(always)]
|
||||
pub unsafe fn read(&self) -> T {
|
||||
pub unsafe fn assume_init_read(&self) -> T {
|
||||
// SAFETY: the caller must guarantee that `self` is initialized.
|
||||
// Reading from `self.as_ptr()` is safe since `self` should be initialized.
|
||||
unsafe {
|
||||
|
|
Loading…
Reference in New Issue