Skip to content

Commit 0e62990

Browse files
committed
Clarify ManuallyDrop docs
Mention that you can use `into_inner` to drop the contained value.
1 parent 4efc0a7 commit 0e62990

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libcore/mem.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,16 @@ impl<T> ManuallyDrop<T> {
971971
ManuallyDrop { value }
972972
}
973973

974-
/// Extract the value from the ManuallyDrop container.
974+
/// Extract the value from the `ManuallyDrop` container.
975+
///
976+
/// This allows the value to be dropped again.
975977
///
976978
/// # Examples
977979
///
978980
/// ```rust
979981
/// use std::mem::ManuallyDrop;
980982
/// let x = ManuallyDrop::new(Box::new(()));
981-
/// let _: Box<()> = ManuallyDrop::into_inner(x);
983+
/// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`.
982984
/// ```
983985
#[stable(feature = "manually_drop", since = "1.20.0")]
984986
#[inline]
@@ -990,11 +992,15 @@ impl<T> ManuallyDrop<T> {
990992
impl<T: ?Sized> ManuallyDrop<T> {
991993
/// Manually drops the contained value.
992994
///
995+
/// If you have ownership of the value, you can use [`ManuallyDrop::into_inner`] instead.
996+
///
993997
/// # Safety
994998
///
995999
/// This function runs the destructor of the contained value and thus the wrapped value
9961000
/// now represents uninitialized data. It is up to the user of this method to ensure the
9971001
/// uninitialized data is not actually used.
1002+
///
1003+
/// [`ManuallyDrop::into_inner`]: #method.into_inner
9981004
#[stable(feature = "manually_drop", since = "1.20.0")]
9991005
#[inline]
10001006
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {

0 commit comments

Comments
 (0)