diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-28 04:12:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-28 04:12:09 +0200 |
| commit | 9412316ac39db2a91284d809e2ada9c69afe5b50 (patch) | |
| tree | 35675b2780a562effc41ab8e4f5ff8f32e78b469 | |
| parent | 62523045ec681ee8c2ecb8d395fbcaccf336284b (diff) | |
| parent | 01b9fac09924de8be7fd3479d8a900f57b9c710f (diff) | |
| download | rust-9412316ac39db2a91284d809e2ada9c69afe5b50.tar.gz rust-9412316ac39db2a91284d809e2ada9c69afe5b50.zip | |
Rollup merge of #88375 - joshlf:patch-3, r=dtolnay
Clarify that ManuallyDrop<T> has same layout as T This PR implements the documentation change under discussion in https://github.com/rust-lang/unsafe-code-guidelines/issues/302. It should not be approved or merged until the discussion there is resolved.
| -rw-r--r-- | library/core/src/mem/manually_drop.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/library/core/src/mem/manually_drop.rs b/library/core/src/mem/manually_drop.rs index f577f102e8d..3d719afe49e 100644 --- a/library/core/src/mem/manually_drop.rs +++ b/library/core/src/mem/manually_drop.rs @@ -4,11 +4,12 @@ use crate::ptr; /// 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 its contents. For example, initializing a `ManuallyDrop<&mut T>` -/// with [`mem::zeroed`] is undefined behavior. -/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead. +/// `ManuallyDrop<T>` is guaranteed to have the same layout as `T`, and is subject +/// to the same layout optimizations as `T`. As a consequence, it has *no effect* +/// on the assumptions that the compiler makes about its contents. For example, +/// initializing a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined +/// behavior. If you need to handle uninitialized data, use [`MaybeUninit<T>`] +/// instead. /// /// Note that accessing the value inside a `ManuallyDrop<T>` is safe. /// This means that a `ManuallyDrop<T>` whose content has been dropped must not |
