diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-06-18 15:20:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 15:20:59 -0700 |
| commit | 9f8f994ad9cc996b304a90e5ca7c1d894c7eff4d (patch) | |
| tree | d2a4d34bcd2b070dcbb34d59de68cb97ea67b287 | |
| parent | 9ca811772c2fddefeda4567cdfb8c790c94e0085 (diff) | |
| parent | 2da9ca72bcdc6b67fbacf26d9245da367089a113 (diff) | |
| download | rust-9f8f994ad9cc996b304a90e5ca7c1d894c7eff4d.tar.gz rust-9f8f994ad9cc996b304a90e5ca7c1d894c7eff4d.zip | |
Rollup merge of #73425 - poliorcetics:zeroed-functions-pointers, r=dtolnay
Mention functions pointers in the documentation Fixes #51615. This mentions function pointers in the documentation for `core::mem::zeroed`, adding them to the list of types that are **always** wrong when zeroed, with `&T` and `&mut T`. @rustbot modify labels: T-doc, C-enhancement, T-libs
| -rw-r--r-- | src/libcore/mem/mod.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index 8bce980cadd..066bb8b3dc7 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -581,11 +581,12 @@ pub const fn needs_drop<T>() -> 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` and `&mut T`). 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. +/// 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 functions 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. @@ -612,6 +613,7 @@ pub const fn needs_drop<T>() -> bool { /// use std::mem; /// /// let _x: &i32 = unsafe { mem::zeroed() }; // Undefined behavior! +/// let _y: fn() = unsafe { mem::zeroed() }; // And again! /// ``` #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] |
