Skip to content

Commit 444f449

Browse files
authored
Rollup merge of #72277 - RalfJung:manually-drop-docs, r=Mark-Simulacrum
emphasize that ManuallyDrop is safe-to-access and unsafe-to-drop This seems to sometimes confused people, and generally seems reasonable to state in the top-level summary of the type.
2 parents fc91043 + 993c448 commit 444f449

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libcore/mem/manually_drop.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::ops::{Deref, DerefMut};
22
use crate::ptr;
33

44
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
5-
///
65
/// This wrapper is 0-cost.
76
///
87
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
@@ -11,6 +10,11 @@ use crate::ptr;
1110
/// with [`mem::zeroed`] is undefined behavior.
1211
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
1312
///
13+
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe.
14+
/// This means that a `ManuallyDrop<T>` whose content has been dropped must not
15+
/// be exposed through a public safe API.
16+
/// Correspondingly, `ManuallyDrop::drop` is unsafe.
17+
///
1418
/// # Examples
1519
///
1620
/// This wrapper can be used to enforce a particular drop order on fields, regardless

0 commit comments

Comments
 (0)