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.
This commit is contained in:
commit
9412316ac3
1 changed files with 6 additions and 5 deletions
|
@ -4,11 +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 subject to the same layout optimizations as `T`.
|
/// `ManuallyDrop<T>` is guaranteed to have the same layout as `T`, and is subject
|
||||||
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
|
/// to the same layout optimizations as `T`. As a consequence, it has *no effect*
|
||||||
/// about its contents. For example, initializing a `ManuallyDrop<&mut T>`
|
/// on the assumptions that the compiler makes about its contents. For example,
|
||||||
/// with [`mem::zeroed`] is undefined behavior.
|
/// initializing a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined
|
||||||
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
|
/// behavior. If you need to handle uninitialized data, use [`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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue