@@ -580,17 +580,23 @@ impl<T> MaybeUninit<T> {
580
580
///
581
581
/// # Safety
582
582
///
583
- /// Calling this when the content is not yet fully initialized causes undefined
584
- /// behavior: it is up to the caller to guarantee that the `MaybeUninit<T>` really
585
- /// is in an initialized state.
586
- ///
587
- /// This function runs the destructor of the contained value in place.
588
- /// Afterwards, the memory is considered uninitialized again, but remains unmodified.
583
+ /// It is up to the caller to guarantee that the `MaybeUninit<T>` really is
584
+ /// in an initialized state. Calling this when the content is not yet fully
585
+ /// initialized causes undefined behavior.
586
+ ///
587
+ /// On top of that, all additional invariants of the type `T` must be
588
+ /// satisfied, as the `Drop` implementation of `T` (or its members) may
589
+ /// rely on this. For example, a `1`-initialized [`Vec<T>`] is considered
590
+ /// initialized (under the current implementation; this does not constitute
591
+ /// a stable guarantee) because the only requirement the compiler knows
592
+ /// about it is that the data pointer must be non-null. Dropping such a
593
+ /// `Vec<T>` however will cause undefined behaviour.
589
594
///
590
595
/// [`assume_init`]: MaybeUninit::assume_init
591
596
#[ unstable( feature = "maybe_uninit_extra" , issue = "63567" ) ]
592
597
pub unsafe fn assume_init_drop ( & mut self ) {
593
- // SAFETY: the caller must guarantee that `self` is initialized.
598
+ // SAFETY: the caller must guarantee that `self` is initialized and
599
+ // satisfies all invariants of `T`.
594
600
// Dropping the value in place is safe if that is the case.
595
601
unsafe { ptr:: drop_in_place ( self . as_mut_ptr ( ) ) }
596
602
}
0 commit comments