146146
147147#![ stable( feature = "rust1" , since = "1.0.0" ) ]
148148
149+ use crate :: co_alloc:: CoAllocPref ;
149150use core:: any:: Any ;
150151use core:: async_iter:: AsyncIterator ;
151152use core:: borrow;
@@ -642,7 +643,9 @@ impl<T> Box<[T]> {
642643 #[ must_use]
643644 pub fn new_uninit_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
644645 // false = no need for co-alloc metadata, since it would get lost once converted to Box.
645- unsafe { RawVec :: < T , Global , false > :: with_capacity ( len) . into_box ( len) }
646+ unsafe {
647+ RawVec :: < T , Global , { CO_ALLOC_PREF_META_NO ! ( ) } > :: with_capacity ( len) . into_box ( len)
648+ }
646649 }
647650
648651 /// Constructs a new boxed slice with uninitialized contents, with the memory
@@ -668,7 +671,10 @@ impl<T> Box<[T]> {
668671 #[ must_use]
669672 pub fn new_zeroed_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
670673 // false = no need for co-alloc metadata, since it would get lost once converted to Box.
671- unsafe { RawVec :: < T , Global , false > :: with_capacity_zeroed ( len) . into_box ( len) }
674+ unsafe {
675+ RawVec :: < T , Global , { CO_ALLOC_PREF_META_NO ! ( ) } > :: with_capacity_zeroed ( len)
676+ . into_box ( len)
677+ }
672678 }
673679
674680 /// Constructs a new boxed slice with uninitialized contents. Returns an error if
@@ -700,7 +706,7 @@ impl<T> Box<[T]> {
700706 Err ( _) => return Err ( AllocError ) ,
701707 } ;
702708 let ptr = Global . allocate ( layout) ?;
703- Ok ( RawVec :: < T , Global , false > :: from_raw_parts_in (
709+ Ok ( RawVec :: < T , Global , { CO_ALLOC_PREF_META_NO ! ( ) } > :: from_raw_parts_in (
704710 ptr. as_mut_ptr ( ) as * mut _ ,
705711 len,
706712 Global ,
@@ -737,7 +743,7 @@ impl<T> Box<[T]> {
737743 Err ( _) => return Err ( AllocError ) ,
738744 } ;
739745 let ptr = Global . allocate_zeroed ( layout) ?;
740- Ok ( RawVec :: < T , Global , false > :: from_raw_parts_in (
746+ Ok ( RawVec :: < T , Global , { CO_ALLOC_PREF_META_NO ! ( ) } > :: from_raw_parts_in (
741747 ptr. as_mut_ptr ( ) as * mut _ ,
742748 len,
743749 Global ,
@@ -747,9 +753,10 @@ impl<T> Box<[T]> {
747753 }
748754}
749755
756+ #[ allow( unused_braces) ]
750757impl < T , A : Allocator > Box < [ T ] , A >
751758where
752- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots :: < A > ( ) ] : ,
759+ [ ( ) ; { crate :: meta_num_slots! ( A , crate :: CO_ALLOC_PREF_META_NO ! ( ) ) } ] : ,
753760{
754761 /// Constructs a new boxed slice with uninitialized contents in the provided allocator.
755762 ///
@@ -778,12 +785,10 @@ where
778785 // #[unstable(feature = "new_uninit", issue = "63291")]
779786 #[ must_use]
780787 #[ allow( unused_braces) ]
781- pub fn new_uninit_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A >
782- where
783- // false = no need for co-alloc metadata, since it would get lost once converted to Box.
784- [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( false ) ] : ,
785- {
786- unsafe { RawVec :: < T , A , false > :: with_capacity_in ( len, alloc) . into_box ( len) }
788+ pub fn new_uninit_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A > {
789+ unsafe {
790+ RawVec :: < T , A , { CO_ALLOC_PREF_META_NO ! ( ) } > :: with_capacity_in ( len, alloc) . into_box ( len)
791+ }
787792 }
788793
789794 /// Constructs a new boxed slice with uninitialized contents in the provided allocator,
@@ -811,12 +816,11 @@ where
811816 // #[unstable(feature = "new_uninit", issue = "63291")]
812817 #[ must_use]
813818 #[ allow( unused_braces) ]
814- pub fn new_zeroed_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A >
815- where
816- // false = no need for co-alloc metadata, since it would get lost once converted to Box.
817- [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( false ) ] : ,
818- {
819- unsafe { RawVec :: < T , A , false > :: with_capacity_zeroed_in ( len, alloc) . into_box ( len) }
819+ pub fn new_zeroed_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A > {
820+ unsafe {
821+ RawVec :: < T , A , { CO_ALLOC_PREF_META_NO ! ( ) } > :: with_capacity_zeroed_in ( len, alloc)
822+ . into_box ( len)
823+ }
820824 }
821825}
822826
@@ -1522,7 +1526,7 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
15221526 fn from ( slice : & [ T ] ) -> Box < [ T ] > {
15231527 let len = slice. len ( ) ;
15241528 // false = no need for co-alloc metadata, since it would get lost once converted to Box.
1525- let buf = RawVec :: < T , Global , false > :: with_capacity ( len) ;
1529+ let buf = RawVec :: < T , Global , { CO_ALLOC_PREF_META_NO ! ( ) } > :: with_capacity ( len) ;
15261530 unsafe {
15271531 ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , buf. ptr ( ) , len) ;
15281532 buf. into_box ( slice. len ( ) ) . assume_init ( )
@@ -1687,12 +1691,13 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
16871691
16881692#[ cfg( not( no_global_oom_handling) ) ]
16891693#[ stable( feature = "boxed_array_try_from_vec" , since = "1.66.0" ) ]
1690- impl < T , const N : usize , const COOP_PREFERRED : bool > TryFrom < Vec < T , Global , COOP_PREFERRED > >
1694+ #[ allow( unused_braces) ]
1695+ impl < T , const N : usize , const CO_ALLOC_PREF : CoAllocPref > TryFrom < Vec < T , Global , CO_ALLOC_PREF > >
16911696 for Box < [ T ; N ] >
16921697where
1693- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
1698+ [ ( ) ; { meta_num_slots_global ! ( CO_ALLOC_PREF ) } ] : ,
16941699{
1695- type Error = Vec < T , Global , COOP_PREFERRED > ;
1700+ type Error = Vec < T , Global , CO_ALLOC_PREF > ;
16961701
16971702 /// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
16981703 ///
@@ -1712,7 +1717,7 @@ where
17121717 /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
17131718 /// assert_eq!(state.len(), 100);
17141719 /// ```
1715- fn try_from ( vec : Vec < T , Global , COOP_PREFERRED > ) -> Result < Self , Self :: Error > {
1720+ fn try_from ( vec : Vec < T , Global , CO_ALLOC_PREF > ) -> Result < Self , Self :: Error > {
17161721 if vec. len ( ) == N {
17171722 let boxed_slice = vec. into_boxed_slice ( ) ;
17181723 Ok ( unsafe { boxed_slice_as_array_unchecked ( boxed_slice) } )
@@ -2049,14 +2054,15 @@ impl<I> FromIterator<I> for Box<[I]> {
20492054
20502055#[ cfg( not( no_global_oom_handling) ) ]
20512056#[ stable( feature = "box_slice_clone" , since = "1.3.0" ) ]
2057+ #[ allow( unused_braces) ]
20522058impl < T : Clone , A : Allocator + Clone > Clone for Box < [ T ] , A >
20532059where
2054- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots_with_preference :: < A > ( false ) ] : ,
2060+ [ ( ) ; { crate :: meta_num_slots! ( A , crate :: CO_ALLOC_PREF_META_NO ! ( ) ) } ] : ,
20552061{
20562062 fn clone ( & self ) -> Self {
20572063 let alloc = Box :: allocator ( self ) . clone ( ) ;
20582064 // false = no need for co-alloc metadata, since it would get lost once converted to the boxed slice.
2059- self . to_vec_in :: < A , false > ( alloc) . into_boxed_slice ( )
2065+ self . to_vec_in_co :: < A , { CO_ALLOC_PREF_META_NO ! ( ) } > ( alloc) . into_boxed_slice ( )
20602066 }
20612067
20622068 fn clone_from ( & mut self , other : & Self ) {
0 commit comments