Skip to content

Commit 4520a39

Browse files
authored
Rollup merge of rust-lang#63215 - gnzlbg:patch-6, r=Centril
Clarify semantics of mem::zeroed Clarifies the semantics of `mem::zeroed`. r? @Centril cc @RalfJung
2 parents f6d8977 + 3725e35 commit 4520a39

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libcore/mem/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,20 @@ pub const fn needs_drop<T>() -> bool {
414414
intrinsics::needs_drop::<T>()
415415
}
416416

417-
/// Creates a value whose bytes are all zero.
417+
/// Returns the value of type `T` represented by the all-zero byte-pattern.
418418
///
419-
/// This has the same effect as [`MaybeUninit::zeroed().assume_init()`][zeroed].
420-
/// It is useful for FFI sometimes, but should generally be avoided.
419+
/// This means that, for example, the padding byte in `(u8, u16)` is not
420+
/// necessarily zeroed.
421421
///
422422
/// There is no guarantee that an all-zero byte-pattern represents a valid value of
423423
/// some type `T`. For example, the all-zero byte-pattern is not a valid value
424424
/// for reference types (`&T` and `&mut T`). Using `zeroed` on such types
425425
/// causes immediate [undefined behavior][ub] because [the Rust compiler assumes][inv]
426426
/// that there always is a valid value in a variable it considers initialized.
427427
///
428+
/// This has the same effect as [`MaybeUninit::zeroed().assume_init()`][zeroed].
429+
/// It is useful for FFI sometimes, but should generally be avoided.
430+
///
428431
/// [zeroed]: union.MaybeUninit.html#method.zeroed
429432
/// [ub]: ../../reference/behavior-considered-undefined.html
430433
/// [inv]: union.MaybeUninit.html#initialization-invariant

0 commit comments

Comments
 (0)