@@ -369,7 +369,7 @@ impl<T> MaybeUninit<T> {
369369 pub fn write ( & mut self , val : T ) -> & mut T {
370370 unsafe {
371371 self . value = ManuallyDrop :: new ( val) ;
372- self . get_mut ( )
372+ self . assume_init_mut ( )
373373 }
374374 }
375375
@@ -601,7 +601,7 @@ impl<T> MaybeUninit<T> {
601601 /// // create a shared reference to it:
602602 /// let x: &Vec<u32> = unsafe {
603603 /// // Safety: `x` has been initialized.
604- /// x.get_ref ()
604+ /// x.assume_init_ref ()
605605 /// };
606606 /// assert_eq!(x, &vec![1, 2, 3]);
607607 /// ```
@@ -613,7 +613,7 @@ impl<T> MaybeUninit<T> {
613613 /// use std::mem::MaybeUninit;
614614 ///
615615 /// let x = MaybeUninit::<Vec<u32>>::uninit();
616- /// let x_vec: &Vec<u32> = unsafe { x.get_ref () };
616+ /// let x_vec: &Vec<u32> = unsafe { x.assume_init_ref () };
617617 /// // We have created a reference to an uninitialized vector! This is undefined behavior. ⚠️
618618 /// ```
619619 ///
@@ -624,14 +624,14 @@ impl<T> MaybeUninit<T> {
624624 /// let b = MaybeUninit::<Cell<bool>>::uninit();
625625 /// // Initialize the `MaybeUninit` using `Cell::set`:
626626 /// unsafe {
627- /// b.get_ref ().set(true);
628- /// // ^^^^^^^^^^^
629- /// // Reference to an uninitialized `Cell<bool>`: UB!
627+ /// b.assume_init_ref ().set(true);
628+ /// // ^^^^ ^^^^^^^^^^^
629+ /// // Reference to an uninitialized `Cell<bool>`: UB!
630630 /// }
631631 /// ```
632632 #[ unstable( feature = "maybe_uninit_ref" , issue = "63568" ) ]
633633 #[ inline( always) ]
634- pub unsafe fn get_ref ( & self ) -> & T {
634+ pub unsafe fn assume_init_ref ( & self ) -> & T {
635635 // SAFETY: the caller must guarantee that `self` is initialized.
636636 // This also means that `self` must be a `value` variant.
637637 unsafe {
@@ -650,7 +650,7 @@ impl<T> MaybeUninit<T> {
650650 ///
651651 /// Calling this when the content is not yet fully initialized causes undefined
652652 /// behavior: it is up to the caller to guarantee that the `MaybeUninit<T>` really
653- /// is in an initialized state. For instance, `.get_mut ()` cannot be used to
653+ /// is in an initialized state. For instance, `.assume_init_mut ()` cannot be used to
654654 /// initialize a `MaybeUninit`.
655655 ///
656656 /// # Examples
@@ -678,7 +678,7 @@ impl<T> MaybeUninit<T> {
678678 /// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
679679 /// let buf: &mut [u8; 2048] = unsafe {
680680 /// // Safety: `buf` has been initialized.
681- /// buf.get_mut ()
681+ /// buf.assume_init_mut ()
682682 /// };
683683 ///
684684 /// // Now we can use `buf` as a normal slice:
@@ -691,15 +691,15 @@ impl<T> MaybeUninit<T> {
691691 ///
692692 /// ### *Incorrect* usages of this method:
693693 ///
694- /// You cannot use `.get_mut ()` to initialize a value:
694+ /// You cannot use `.assume_init_mut ()` to initialize a value:
695695 ///
696696 /// ```rust,no_run
697697 /// #![feature(maybe_uninit_ref)]
698698 /// use std::mem::MaybeUninit;
699699 ///
700700 /// let mut b = MaybeUninit::<bool>::uninit();
701701 /// unsafe {
702- /// *b.get_mut () = true;
702+ /// *b.assume_init_mut () = true;
703703 /// // We have created a (mutable) reference to an uninitialized `bool`!
704704 /// // This is undefined behavior. ⚠️
705705 /// }
@@ -716,8 +716,8 @@ impl<T> MaybeUninit<T> {
716716 /// fn read_chunk (reader: &'_ mut dyn io::Read) -> io::Result<[u8; 64]>
717717 /// {
718718 /// let mut buffer = MaybeUninit::<[u8; 64]>::uninit();
719- /// reader.read_exact(unsafe { buffer.get_mut () })?;
720- /// // ^^^^^^^^^^^^^^^^
719+ /// reader.read_exact(unsafe { buffer.assume_init_mut () })?;
720+ /// // ^^^^^^^^^^^^^^^^^^^^^^^^
721721 /// // (mutable) reference to uninitialized memory!
722722 /// // This is undefined behavior.
723723 /// Ok(unsafe { buffer.assume_init() })
@@ -737,23 +737,23 @@ impl<T> MaybeUninit<T> {
737737 ///
738738 /// let foo: Foo = unsafe {
739739 /// let mut foo = MaybeUninit::<Foo>::uninit();
740- /// ptr::write(&mut foo.get_mut ().a as *mut u32, 1337);
741- /// // ^^^^^^^^^^^^^
740+ /// ptr::write(&mut foo.assume_init_mut ().a as *mut u32, 1337);
741+ /// // ^^^^^^^^^^^^^^^^^^^^^
742742 /// // (mutable) reference to uninitialized memory!
743743 /// // This is undefined behavior.
744- /// ptr::write(&mut foo.get_mut ().b as *mut u8, 42);
745- /// // ^^^^^^^^^^^^^
744+ /// ptr::write(&mut foo.assume_init_mut ().b as *mut u8, 42);
745+ /// // ^^^^^^^^^^^^^^^^^^^^^
746746 /// // (mutable) reference to uninitialized memory!
747747 /// // This is undefined behavior.
748748 /// foo.assume_init()
749749 /// };
750750 /// ```
751- // FIXME(#53491 ): We currently rely on the above being incorrect, i.e., we have references
751+ // FIXME(#76092 ): We currently rely on the above being incorrect, i.e., we have references
752752 // to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make
753753 // a final decision about the rules before stabilization.
754754 #[ unstable( feature = "maybe_uninit_ref" , issue = "63568" ) ]
755755 #[ inline( always) ]
756- pub unsafe fn get_mut ( & mut self ) -> & mut T {
756+ pub unsafe fn assume_init_mut ( & mut self ) -> & mut T {
757757 // SAFETY: the caller must guarantee that `self` is initialized.
758758 // This also means that `self` must be a `value` variant.
759759 unsafe {
0 commit comments