@@ -520,8 +520,8 @@ impl<T> MaybeUninit<T> {
520
520
/// this initialization invariant.
521
521
///
522
522
/// 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
525
525
/// to ensure that that data may indeed be duplicated.
526
526
///
527
527
/// [inv]: #initialization-invariant
@@ -537,16 +537,16 @@ impl<T> MaybeUninit<T> {
537
537
///
538
538
/// let mut x = MaybeUninit::<u32>::uninit();
539
539
/// x.write(13);
540
- /// let x1 = unsafe { x.read () };
540
+ /// let x1 = unsafe { x.assume_init_read () };
541
541
/// // `u32` is `Copy`, so we may read multiple times.
542
- /// let x2 = unsafe { x.read () };
542
+ /// let x2 = unsafe { x.assume_init_read () };
543
543
/// assert_eq!(x1, x2);
544
544
///
545
545
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
546
546
/// x.write(None);
547
- /// let x1 = unsafe { x.read () };
547
+ /// let x1 = unsafe { x.assume_init_read () };
548
548
/// // 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 () };
550
550
/// assert_eq!(x1, x2);
551
551
/// ```
552
552
///
@@ -558,14 +558,14 @@ impl<T> MaybeUninit<T> {
558
558
///
559
559
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
560
560
/// 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 () };
563
563
/// // We now created two copies of the same vector, leading to a double-free ⚠️ when
564
564
/// // they both get dropped!
565
565
/// ```
566
566
#[ unstable( feature = "maybe_uninit_extra" , issue = "63567" ) ]
567
567
#[ inline( always) ]
568
- pub unsafe fn read ( & self ) -> T {
568
+ pub unsafe fn assume_init_read ( & self ) -> T {
569
569
// SAFETY: the caller must guarantee that `self` is initialized.
570
570
// Reading from `self.as_ptr()` is safe since `self` should be initialized.
571
571
unsafe {
0 commit comments