Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,18 @@ pub const fn needs_drop<T: ?Sized>() -> bool {
/// This means that, for example, the padding byte in `(u8, u16)` is not
/// necessarily zeroed.
///
/// There is no guarantee that an all-zero byte-pattern represents a valid value
/// of some type `T`. For example, the all-zero byte-pattern is not a valid value
/// for reference types (`&T`, `&mut T`) and function pointers. Using `zeroed`
/// on such types causes immediate [undefined behavior][ub] because [the Rust
/// compiler assumes][inv] that there always is a valid value in a variable it
/// considers initialized.
///
/// This has the same effect as [`MaybeUninit::zeroed().assume_init()`][zeroed].
/// It is useful for FFI sometimes, but should generally be avoided.
///
///
/// # Safety
///
/// The all-zero byte-pattern must represent a valid value of type `T`.
/// For example, it is not valid for reference types (`&T`, `&mut T`) or function
/// pointers. Using `zeroed` on such types causes immediate [undefined behavior][ub]
/// because [the Rust compiler assumes][inv] that there always is a valid value in a
/// variable it considers initialized.
///
/// [zeroed]: MaybeUninit::zeroed
/// [ub]: ../../reference/behavior-considered-undefined.html
/// [inv]: MaybeUninit#initialization-invariant
Expand Down
Loading