diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-03 00:09:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-03 00:09:14 +0200 |
| commit | 4520a39b94a691f58c4a266e2c9d52406dfac414 (patch) | |
| tree | 050db2ef3dad2eef7c9851a6cef6c0a4dd99109b | |
| parent | f6d8977fbb7a97cb49220a7a9eaa7bd26ee0e4a6 (diff) | |
| parent | 3725e3542fdf927dabaabf6f6c4bc1352c309da2 (diff) | |
| download | rust-4520a39b94a691f58c4a266e2c9d52406dfac414.tar.gz rust-4520a39b94a691f58c4a266e2c9d52406dfac414.zip | |
Rollup merge of #63215 - gnzlbg:patch-6, r=Centril
Clarify semantics of mem::zeroed Clarifies the semantics of `mem::zeroed`. r? @Centril cc @RalfJung
| -rw-r--r-- | src/libcore/mem/mod.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index bb81d7b794b..86dae985fdb 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -414,10 +414,10 @@ pub const fn needs_drop<T>() -> bool { intrinsics::needs_drop::<T>() } -/// Creates a value whose bytes are all zero. +/// Returns the value of type `T` represented by the all-zero byte-pattern. /// -/// This has the same effect as [`MaybeUninit::zeroed().assume_init()`][zeroed]. -/// It is useful for FFI sometimes, but should generally be avoided. +/// 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 @@ -425,6 +425,9 @@ pub const fn needs_drop<T>() -> bool { /// 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. +/// /// [zeroed]: union.MaybeUninit.html#method.zeroed /// [ub]: ../../reference/behavior-considered-undefined.html /// [inv]: union.MaybeUninit.html#initialization-invariant |
