Skip to content
Permalink
Browse files

be explicit that mem::uninitialized is the same as MaybeUninit::unini…

…t().assume_init()
  • Loading branch information
RalfJung committed Dec 13, 2019
1 parent 9409c20 commit 216b9ae8780655c001b7401b630a046633e1b3c6
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/libcore/mem/mod.rs
@@ -510,7 +510,9 @@ pub unsafe fn zeroed<T>() -> T {
/// **This function is deprecated.** Use [`MaybeUninit<T>`] instead.
///
/// The reason for deprecation is that the function basically cannot be used
/// correctly: [the Rust compiler assumes][inv] that values are properly initialized.
/// correctly: it has the same effect as [`MaybeUninit::uninit().assume_init()`][uninit].
/// As the [`assume_init` documentation][assume_init] explains,
/// [the Rust compiler assumes][inv] that values are properly initialized.
/// As a consequence, calling e.g. `mem::uninitialized::<bool>()` causes immediate
/// undefined behavior for returning a `bool` that is not definitely either `true`
/// or `false`. Worse, truly uninitialized memory like what gets returned here
@@ -521,6 +523,8 @@ pub unsafe fn zeroed<T>() -> T {
/// until they are, it is advisable to avoid them.)
///
/// [`MaybeUninit<T>`]: union.MaybeUninit.html
/// [uninit]: union.MaybeUninit.html#method.uninit
/// [assume_init]: union.MaybeUninit.html#method.assume_init
/// [inv]: union.MaybeUninit.html#initialization-invariant
#[inline]
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]

0 comments on commit 216b9ae

Please sign in to comment.
You can’t perform that action at this time.