diff options
| author | Kevin Reid <kpreid@switchb.org> | 2024-05-12 21:31:13 -0700 |
|---|---|---|
| committer | Kevin Reid <kpreid@switchb.org> | 2024-06-04 14:40:21 -0700 |
| commit | ac96fa44faa786ad5682e6ed7359842d0e6a4b53 (patch) | |
| tree | dc836ade1b4fa252268ac81f2708391f89067782 | |
| parent | 44701e070c8453df10df1984944258018ac21610 (diff) | |
| download | rust-ac96fa44faa786ad5682e6ed7359842d0e6a4b53.tar.gz rust-ac96fa44faa786ad5682e6ed7359842d0e6a4b53.zip | |
Use inline const instead of unsafe to construct arrays in `MaybeUninit` examples.
| -rw-r--r-- | library/core/src/mem/maybe_uninit.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 026e21586d4..56af7fa9c89 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -120,12 +120,8 @@ use crate::slice; /// use std::mem::{self, MaybeUninit}; /// /// let data = { -/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is -/// // safe because the type we are claiming to have initialized here is a -/// // bunch of `MaybeUninit`s, which do not require initialization. -/// let mut data: [MaybeUninit<Vec<u32>>; 1000] = unsafe { -/// MaybeUninit::uninit().assume_init() -/// }; +/// // Create an uninitialized array of `MaybeUninit`. +/// let mut data: [MaybeUninit<Vec<u32>>; 1000] = [const { MaybeUninit::uninit() }; 1000]; /// /// // Dropping a `MaybeUninit` does nothing, so if there is a panic during this loop, /// // we have a memory leak, but there is no memory safety issue. @@ -147,10 +143,8 @@ use crate::slice; /// ``` /// use std::mem::MaybeUninit; /// -/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is -/// // safe because the type we are claiming to have initialized here is a -/// // bunch of `MaybeUninit`s, which do not require initialization. -/// let mut data: [MaybeUninit<String>; 1000] = unsafe { MaybeUninit::uninit().assume_init() }; +/// // Create an uninitialized array of `MaybeUninit`. +/// let mut data: [MaybeUninit<String>; 1000] = [const { MaybeUninit::uninit() }; 1000]; /// // Count the number of elements we have assigned. /// let mut data_len: usize = 0; /// |
