1
Fork 0

Rollup merge of #53946 - tbu-:pr_doc_manuallydrop, r=cramertj

Clarify `ManuallyDrop` docs

Mention that you can use `into_inner` to drop the contained value.
This commit is contained in:
kennytm 2018-09-07 13:47:17 +08:00
commit 03de1c44d1
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C

View file

@ -971,14 +971,16 @@ impl<T> ManuallyDrop<T> {
ManuallyDrop { value } ManuallyDrop { value }
} }
/// Extract the value from the ManuallyDrop container. /// Extract the value from the `ManuallyDrop` container.
///
/// This allows the value to be dropped again.
/// ///
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use std::mem::ManuallyDrop; /// use std::mem::ManuallyDrop;
/// let x = ManuallyDrop::new(Box::new(())); /// let x = ManuallyDrop::new(Box::new(()));
/// let _: Box<()> = ManuallyDrop::into_inner(x); /// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`.
/// ``` /// ```
#[stable(feature = "manually_drop", since = "1.20.0")] #[stable(feature = "manually_drop", since = "1.20.0")]
#[inline] #[inline]
@ -990,11 +992,15 @@ impl<T> ManuallyDrop<T> {
impl<T: ?Sized> ManuallyDrop<T> { impl<T: ?Sized> ManuallyDrop<T> {
/// Manually drops the contained value. /// Manually drops the contained value.
/// ///
/// If you have ownership of the value, you can use [`ManuallyDrop::into_inner`] instead.
///
/// # Safety /// # Safety
/// ///
/// This function runs the destructor of the contained value and thus the wrapped value /// This function runs the destructor of the contained value and thus the wrapped value
/// now represents uninitialized data. It is up to the user of this method to ensure the /// now represents uninitialized data. It is up to the user of this method to ensure the
/// uninitialized data is not actually used. /// uninitialized data is not actually used.
///
/// [`ManuallyDrop::into_inner`]: #method.into_inner
#[stable(feature = "manually_drop", since = "1.20.0")] #[stable(feature = "manually_drop", since = "1.20.0")]
#[inline] #[inline]
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) { pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {