External Publication
Visit Post

Introduce `Box::new_uninit_array` and `Box::new_zeroed_array`

Rust Internals [Unofficial] April 15, 2026
Source

Because arrays are Sized, we can use the existing new_uninit/new_zeroed to get the right allocation for this…but I don't see a good way to then reinterpret the MaybeUninit to be elementwise. MaybeUninit::transpose does exist (unstably), but it doesn't apply to Boxed arrays. Still, I think that might be a better missing piece to add, rather than new top-level factory methods.

Another alternative is Box::new([MaybeUninit::zeroed(); N]), but then you're trusting the optimizer to eliminate the intermediate copy. So I see the motivation for something here.

Discussion in the ATmosphere

Loading comments...