@@ -369,7 +369,7 @@ impl<T> MaybeUninit<T> {
369
369
pub fn write ( & mut self , val : T ) -> & mut T {
370
370
unsafe {
371
371
self . value = ManuallyDrop :: new ( val) ;
372
- self . get_mut ( )
372
+ self . assume_init_mut ( )
373
373
}
374
374
}
375
375
@@ -601,7 +601,7 @@ impl<T> MaybeUninit<T> {
601
601
/// // create a shared reference to it:
602
602
/// let x: &Vec<u32> = unsafe {
603
603
/// // Safety: `x` has been initialized.
604
- /// x.get_ref ()
604
+ /// x.assume_init_ref ()
605
605
/// };
606
606
/// assert_eq!(x, &vec![1, 2, 3]);
607
607
/// ```
@@ -613,7 +613,7 @@ impl<T> MaybeUninit<T> {
613
613
/// use std::mem::MaybeUninit;
614
614
///
615
615
/// 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 () };
617
617
/// // We have created a reference to an uninitialized vector! This is undefined behavior. ⚠️
618
618
/// ```
619
619
///
@@ -624,14 +624,14 @@ impl<T> MaybeUninit<T> {
624
624
/// let b = MaybeUninit::<Cell<bool>>::uninit();
625
625
/// // Initialize the `MaybeUninit` using `Cell::set`:
626
626
/// 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!
630
630
/// }
631
631
/// ```
632
632
#[ unstable( feature = "maybe_uninit_ref" , issue = "63568" ) ]
633
633
#[ inline( always) ]
634
- pub unsafe fn get_ref ( & self ) -> & T {
634
+ pub unsafe fn assume_init_ref ( & self ) -> & T {
635
635
// SAFETY: the caller must guarantee that `self` is initialized.
636
636
// This also means that `self` must be a `value` variant.
637
637
unsafe {
@@ -650,7 +650,7 @@ impl<T> MaybeUninit<T> {
650
650
///
651
651
/// Calling this when the content is not yet fully initialized causes undefined
652
652
/// 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
654
654
/// initialize a `MaybeUninit`.
655
655
///
656
656
/// # Examples
@@ -678,7 +678,7 @@ impl<T> MaybeUninit<T> {
678
678
/// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
679
679
/// let buf: &mut [u8; 2048] = unsafe {
680
680
/// // Safety: `buf` has been initialized.
681
- /// buf.get_mut ()
681
+ /// buf.assume_init_mut ()
682
682
/// };
683
683
///
684
684
/// // Now we can use `buf` as a normal slice:
@@ -691,15 +691,15 @@ impl<T> MaybeUninit<T> {
691
691
///
692
692
/// ### *Incorrect* usages of this method:
693
693
///
694
- /// You cannot use `.get_mut ()` to initialize a value:
694
+ /// You cannot use `.assume_init_mut ()` to initialize a value:
695
695
///
696
696
/// ```rust,no_run
697
697
/// #![feature(maybe_uninit_ref)]
698
698
/// use std::mem::MaybeUninit;
699
699
///
700
700
/// let mut b = MaybeUninit::<bool>::uninit();
701
701
/// unsafe {
702
- /// *b.get_mut () = true;
702
+ /// *b.assume_init_mut () = true;
703
703
/// // We have created a (mutable) reference to an uninitialized `bool`!
704
704
/// // This is undefined behavior. ⚠️
705
705
/// }
@@ -716,8 +716,8 @@ impl<T> MaybeUninit<T> {
716
716
/// fn read_chunk (reader: &'_ mut dyn io::Read) -> io::Result<[u8; 64]>
717
717
/// {
718
718
/// 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
+ /// // ^^^^^^^^^^^^^^^^^^^^^^^^
721
721
/// // (mutable) reference to uninitialized memory!
722
722
/// // This is undefined behavior.
723
723
/// Ok(unsafe { buffer.assume_init() })
@@ -737,23 +737,23 @@ impl<T> MaybeUninit<T> {
737
737
///
738
738
/// let foo: Foo = unsafe {
739
739
/// 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
+ /// // ^^^^^^^^^^^^^^^^^^^^^
742
742
/// // (mutable) reference to uninitialized memory!
743
743
/// // 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
+ /// // ^^^^^^^^^^^^^^^^^^^^^
746
746
/// // (mutable) reference to uninitialized memory!
747
747
/// // This is undefined behavior.
748
748
/// foo.assume_init()
749
749
/// };
750
750
/// ```
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
752
752
// to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make
753
753
// a final decision about the rules before stabilization.
754
754
#[ unstable( feature = "maybe_uninit_ref" , issue = "63568" ) ]
755
755
#[ inline( always) ]
756
- pub unsafe fn get_mut ( & mut self ) -> & mut T {
756
+ pub unsafe fn assume_init_mut ( & mut self ) -> & mut T {
757
757
// SAFETY: the caller must guarantee that `self` is initialized.
758
758
// This also means that `self` must be a `value` variant.
759
759
unsafe {
0 commit comments