Skip to content

Commit 9412316

Browse files
authored
Rollup merge of rust-lang#88375 - joshlf:patch-3, r=dtolnay
Clarify that ManuallyDrop<T> has same layout as T This PR implements the documentation change under discussion in rust-lang/unsafe-code-guidelines#302. It should not be approved or merged until the discussion there is resolved.
2 parents 6252304 + 01b9fac commit 9412316

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

library/core/src/mem/manually_drop.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use crate::ptr;
44
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
55
/// This wrapper is 0-cost.
66
///
7-
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
8-
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
9-
/// about its contents. For example, initializing a `ManuallyDrop<&mut T>`
10-
/// with [`mem::zeroed`] is undefined behavior.
11-
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
7+
/// `ManuallyDrop<T>` is guaranteed to have the same layout as `T`, and is subject
8+
/// to the same layout optimizations as `T`. As a consequence, it has *no effect*
9+
/// on the assumptions that the compiler makes about its contents. For example,
10+
/// initializing a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined
11+
/// behavior. If you need to handle uninitialized data, use [`MaybeUninit<T>`]
12+
/// instead.
1213
///
1314
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe.
1415
/// This means that a `ManuallyDrop<T>` whose content has been dropped must not

0 commit comments

Comments
 (0)