@@ -468,6 +468,40 @@ impl<T> Arc<[T]> {
468468 pub fn new_uninit_slice ( len : usize ) -> Arc < [ mem:: MaybeUninit < T > ] > {
469469 unsafe { Arc :: from_ptr ( Arc :: allocate_for_slice ( len) ) }
470470 }
471+
472+ /// Constructs a new atomically reference-counted slice with uninitialized contents, with the memory being
473+ /// filled with `0` bytes.
474+ ///
475+ /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and
476+ /// incorrect usage of this method.
477+ ///
478+ /// # Examples
479+ ///
480+ /// ```
481+ /// #![feature(new_uninit)]
482+ ///
483+ /// use std::sync::Arc;
484+ ///
485+ /// let values = Arc::<[u32]>::new_zeroed_slice(3);
486+ /// let values = unsafe { values.assume_init() };
487+ ///
488+ /// assert_eq!(*values, [0, 0, 0])
489+ /// ```
490+ ///
491+ /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
492+ #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
493+ pub fn new_zeroed_slice ( len : usize ) -> Arc < [ mem:: MaybeUninit < T > ] > {
494+ unsafe {
495+ Arc :: from_ptr ( Arc :: allocate_for_layout (
496+ Layout :: array :: < T > ( len) . unwrap ( ) ,
497+ |layout| Global . alloc_zeroed ( layout) ,
498+ |mem| {
499+ ptr:: slice_from_raw_parts_mut ( mem as * mut T , len)
500+ as * mut ArcInner < [ mem:: MaybeUninit < T > ] >
501+ } ,
502+ ) )
503+ }
504+ }
471505}
472506
473507impl < T > Arc < mem:: MaybeUninit < T > > {
0 commit comments