diff options
| author | gnzlbg <gnzlbg@users.noreply.github.com> | 2019-08-02 13:39:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-02 13:39:07 +0200 |
| commit | 57f94237e1ae9be36583270efacaa6556dbc1ce0 (patch) | |
| tree | 4a4033585a0b2292c14c1c05a300b010162987e0 /src/libcore | |
| parent | fc3ef9698fa80aa2f4da6208b8295bc8fa48eec5 (diff) | |
| download | rust-57f94237e1ae9be36583270efacaa6556dbc1ce0.tar.gz rust-57f94237e1ae9be36583270efacaa6556dbc1ce0.zip | |
Clarify semantics of mem::zeroed
Diffstat (limited to 'src/libcore')
| -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..56aa145c56c 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-zeros bit-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 |
