Skip to content

Commit

Permalink
Match core's definition of uninit_array (#12)
Browse files Browse the repository at this point in the history
Since we specifically bound on `ArrayType = [T; N]` it's possible to
write that directly.

Using the exact same code as core should help ensure and inspire
confidence that it's implemented correctly.

Note: a TODO still suggests using the upstream `core` method when it's
been stabilized
  • Loading branch information
tarcieri authored Jan 14, 2024
1 parent 5510e29 commit 0bbdfff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ where
// for a `MaybeUninit`: it's a type for representing potentially uninitialized memory (and
// in this case it's uninitialized).
//
// See how `core` defines `MaybeUninit::uninit_array` for a similar example:
// This is identical to how `core` implements `MaybeUninit::uninit_array`:
// <https://github.com/rust-lang/rust/blob/917f654/library/core/src/mem/maybe_uninit.rs#L350-L352>
// TODO(tarcieri): use `MaybeUninit::uninit_array` when stable
Self(unsafe { MaybeUninit::<U::ArrayType<MaybeUninit<T>>>::uninit().assume_init() })
Self(unsafe { MaybeUninit::<[MaybeUninit<T>; N]>::uninit().assume_init() })
}

/// Extract the values from an array of `MaybeUninit` containers.
Expand Down

0 comments on commit 0bbdfff

Please sign in to comment.