From 57f94237e1ae9be36583270efacaa6556dbc1ce0 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 2 Aug 2019 13:39:07 +0200 Subject: [PATCH 1/3] Clarify semantics of mem::zeroed --- src/libcore/mem/mod.rs | 9 ++++++--- 1 file 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() -> bool { intrinsics::needs_drop::() } -/// 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() -> 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 From 13b4afe4baf0080cb1392d8e4009fee31c4b95ea Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 2 Aug 2019 14:12:12 +0200 Subject: [PATCH 2/3] Remove trailing whitespace I had one job... --- src/libcore/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index 56aa145c56c..c4f8747bb78 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -417,7 +417,7 @@ pub const fn needs_drop() -> bool { /// Returns the value of type `T` represented by the all-zeros bit-pattern. /// /// This means that, for example, the padding byte in `(u8, u16)` is not -/// necessarily zeroed. +/// 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 From 3725e3542fdf927dabaabf6f6c4bc1352c309da2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 2 Aug 2019 15:07:19 +0200 Subject: [PATCH 3/3] Consistency. --- src/libcore/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index c4f8747bb78..86dae985fdb 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -414,7 +414,7 @@ pub const fn needs_drop() -> bool { intrinsics::needs_drop::() } -/// Returns the value of type `T` represented by the all-zeros bit-pattern. +/// Returns the value of type `T` represented by the all-zero byte-pattern. /// /// This means that, for example, the padding byte in `(u8, u16)` is not /// necessarily zeroed.