File tree 1 file changed +4
-6
lines changed
1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ use crate::fmt;
3
3
use crate :: intrinsics;
4
4
use crate :: mem:: ManuallyDrop ;
5
5
6
- // ignore-tidy-undocumented-unsafe
7
-
8
6
/// A wrapper type to construct uninitialized instances of `T`.
9
7
///
10
8
/// # Initialization invariant
@@ -355,6 +353,7 @@ impl<T> MaybeUninit<T> {
355
353
#[ rustc_diagnostic_item = "maybe_uninit_zeroed" ]
356
354
pub fn zeroed ( ) -> MaybeUninit < T > {
357
355
let mut u = MaybeUninit :: < T > :: uninit ( ) ;
356
+ // SAFETY: `u.as_mut_ptr()` points to allocated memory.
358
357
unsafe {
359
358
u. as_mut_ptr ( ) . write_bytes ( 0u8 , 1 ) ;
360
359
}
@@ -368,10 +367,9 @@ impl<T> MaybeUninit<T> {
368
367
#[ unstable( feature = "maybe_uninit_extra" , issue = "63567" ) ]
369
368
#[ inline( always) ]
370
369
pub fn write ( & mut self , val : T ) -> & mut T {
371
- unsafe {
372
- self . value = ManuallyDrop :: new ( val) ;
373
- self . assume_init_mut ( )
374
- }
370
+ * self = MaybeUninit :: new ( val) ;
371
+ // SAFETY: We just initialized this value.
372
+ unsafe { self . assume_init_mut ( ) }
375
373
}
376
374
377
375
/// Gets a pointer to the contained value. Reading from this pointer or turning it
You can’t perform that action at this time.
0 commit comments