Skip to content

Commit

Permalink
Use inline const instead of unsafe to implement `MaybeUninit::uninit_…
Browse files Browse the repository at this point in the history
…array()`.
  • Loading branch information
kpreid committed Jun 4, 2024
1 parent ac96fa4 commit ec8fa17
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ impl<T> MaybeUninit<T> {
#[must_use]
#[inline(always)]
pub const fn uninit_array<const N: usize>() -> [Self; N] {
// SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid.
unsafe { MaybeUninit::<[MaybeUninit<T>; N]>::uninit().assume_init() }
[const { MaybeUninit::uninit() }; N]
}

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

0 comments on commit ec8fa17

Please sign in to comment.