Rollup merge of #115522 - joshlf:patch-8, r=scottmcm

Clarify ManuallyDrop bit validity

Clarify that `ManuallyDrop<T>` has the same bit validity as `T`.
This commit is contained in:
Guillaume Gomez 2023-10-06 13:18:33 +02:00 committed by GitHub
commit 525c661842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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