Rollup merge of #125995 - kpreid:const-uninit-stable, r=Nilstrieb · model-checking/verify-rust-std@1632165 (original) (raw)

`@@ -120,12 +120,8 @@ use crate::slice;

`

120

120

`/// use std::mem::{self, MaybeUninit};

`

121

121

`///

`

122

122

`/// let data = {

`

123

``

`` -

/// // Create an uninitialized array of MaybeUninit. The assume_init is

``

124

``

`-

/// // safe because the type we are claiming to have initialized here is a

`

125

``

`` -

/// // bunch of MaybeUninits, which do not require initialization.

``

126

``

`-

/// let mut data: [MaybeUninit<Vec>; 1000] = unsafe {

`

127

``

`-

/// MaybeUninit::uninit().assume_init()

`

128

``

`-

/// };

`

``

123

`` +

/// // Create an uninitialized array of MaybeUninit.

``

``

124

`+

/// let mut data: [MaybeUninit<Vec>; 1000] = [const { MaybeUninit::uninit() }; 1000];

`

129

125

`///

`

130

126

`` /// // Dropping a MaybeUninit does nothing, so if there is a panic during this loop,

``

131

127

`/// // we have a memory leak, but there is no memory safety issue.

`

`@@ -147,10 +143,8 @@ use crate::slice;

`

147

143

```` /// ```

````

148

144

`/// use std::mem::MaybeUninit;

`

149

145

`///

`

150

``

`` -

/// // Create an uninitialized array of MaybeUninit. The assume_init is

``

151

``

`-

/// // safe because the type we are claiming to have initialized here is a

`

152

``

`` -

/// // bunch of MaybeUninits, which do not require initialization.

``

153

``

`-

/// let mut data: [MaybeUninit; 1000] = unsafe { MaybeUninit::uninit().assume_init() };

`

``

146

`` +

/// // Create an uninitialized array of MaybeUninit.

``

``

147

`+

/// let mut data: [MaybeUninit; 1000] = [const { MaybeUninit::uninit() }; 1000];

`

154

148

`/// // Count the number of elements we have assigned.

`

155

149

`/// let mut data_len: usize = 0;

`

156

150

`///

`

`@@ -348,8 +342,7 @@ impl MaybeUninit {

`

348

342

`#[must_use]

`

349

343

`#[inline(always)]

`

350

344

`pub const fn uninit_array() -> [Self; N] {

`

351

``

`` -

// SAFETY: An uninitialized [MaybeUninit<_>; LEN] is valid.

``

352

``

`-

unsafe { MaybeUninit::<[MaybeUninit; N]>::uninit().assume_init() }

`

``

345

`+

[const { MaybeUninit::uninit() }; N]

`

353

346

`}

`

354

347

``

355

348

`` /// Creates a new MaybeUninit<T> in an uninitialized state, with the memory being

``