mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Use inline const instead of unsafe to construct arrays in MaybeUninit examples.
This commit is contained in:
@@ -120,12 +120,8 @@
|
||||
/// 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 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;
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user