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 ad42bc2 commit d150c1c
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 d150c1c

Please sign in to comment.