@@ -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