about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2019-03-02 14:55:11 +0800
committerkennytm <kennytm@gmail.com>2019-03-02 22:58:19 +0800
commitdf2b6bcf5a4bd1acc36c92196cc172ac1a69ca73 (patch)
treeadde0359a2c4c1d82a4f6112a0a4099e58c41ba4
parent2e82d11de1709efe1b89ef73e71550c8fe28b7dd (diff)
parent0c1a38ce3b281ce23b9ba84312f58ba6ac82af57 (diff)
downloadrust-df2b6bcf5a4bd1acc36c92196cc172ac1a69ca73.tar.gz
rust-df2b6bcf5a4bd1acc36c92196cc172ac1a69ca73.zip
Rollup merge of #58780 - RalfJung:manually-drop, r=nagisa
ManuallyDrop != MaybeUninit

Cc @Centril
-rw-r--r--src/libcore/mem.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index f41d293e80a..94f342e7e8e 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -900,10 +900,16 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
     }
 }
 
+// FIXME: Reference `MaybeUninit` from these docs, once that is stable.
 /// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
 ///
 /// This wrapper is 0-cost.
 ///
+/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
+/// As a consequence, it has *no effect* on the assumptions that the compiler makes
+/// about all values being initialized at their type.  In particular, initializing
+/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
+///
 /// # Examples
 ///
 /// 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> {
 ///     }
 /// }
 /// ```
+///
+/// [`mem::zeroed`]: fn.zeroed.html
 #[stable(feature = "manually_drop", since = "1.20.0")]
 #[lang = "manually_drop"]
 #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]