Skip to content

Commit 20409cc

Browse files
authored
Rollup merge of rust-lang#58780 - RalfJung:manually-drop, r=nagisa
ManuallyDrop != MaybeUninit Cc @Centril
2 parents faeba62 + 0c1a38c commit 20409cc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libcore/mem.rs

+8
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,16 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
900900
}
901901
}
902902

903+
// FIXME: Reference `MaybeUninit` from these docs, once that is stable.
903904
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
904905
///
905906
/// This wrapper is 0-cost.
906907
///
908+
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
909+
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
910+
/// about all values being initialized at their type. In particular, initializing
911+
/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
912+
///
907913
/// # Examples
908914
///
909915
/// This wrapper helps with explicitly documenting the drop order dependencies between fields of
@@ -935,6 +941,8 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
935941
/// }
936942
/// }
937943
/// ```
944+
///
945+
/// [`mem::zeroed`]: fn.zeroed.html
938946
#[stable(feature = "manually_drop", since = "1.20.0")]
939947
#[lang = "manually_drop"]
940948
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]

0 commit comments

Comments
 (0)