146
146
147
147
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
148
148
149
+ use crate :: co_alloc:: CoAllocPref ;
149
150
use core:: any:: Any ;
150
151
use core:: async_iter:: AsyncIterator ;
151
152
use core:: borrow;
@@ -642,7 +643,9 @@ impl<T> Box<[T]> {
642
643
#[ must_use]
643
644
pub fn new_uninit_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
644
645
// 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
+ }
646
649
}
647
650
648
651
/// Constructs a new boxed slice with uninitialized contents, with the memory
@@ -668,7 +671,10 @@ impl<T> Box<[T]> {
668
671
#[ must_use]
669
672
pub fn new_zeroed_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
670
673
// 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
+ }
672
678
}
673
679
674
680
/// Constructs a new boxed slice with uninitialized contents. Returns an error if
@@ -700,7 +706,7 @@ impl<T> Box<[T]> {
700
706
Err ( _) => return Err ( AllocError ) ,
701
707
} ;
702
708
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 (
704
710
ptr. as_mut_ptr ( ) as * mut _ ,
705
711
len,
706
712
Global ,
@@ -737,7 +743,7 @@ impl<T> Box<[T]> {
737
743
Err ( _) => return Err ( AllocError ) ,
738
744
} ;
739
745
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 (
741
747
ptr. as_mut_ptr ( ) as * mut _ ,
742
748
len,
743
749
Global ,
@@ -747,9 +753,10 @@ impl<T> Box<[T]> {
747
753
}
748
754
}
749
755
756
+ #[ allow( unused_braces) ]
750
757
impl < T , A : Allocator > Box < [ T ] , A >
751
758
where
752
- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots :: < A > ( ) ] : ,
759
+ [ ( ) ; { crate :: meta_num_slots! ( A , crate :: CO_ALLOC_PREF_META_NO ! ( ) ) } ] : ,
753
760
{
754
761
/// Constructs a new boxed slice with uninitialized contents in the provided allocator.
755
762
///
@@ -778,12 +785,10 @@ where
778
785
// #[unstable(feature = "new_uninit", issue = "63291")]
779
786
#[ must_use]
780
787
#[ 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
+ }
787
792
}
788
793
789
794
/// Constructs a new boxed slice with uninitialized contents in the provided allocator,
@@ -811,12 +816,11 @@ where
811
816
// #[unstable(feature = "new_uninit", issue = "63291")]
812
817
#[ must_use]
813
818
#[ 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
+ }
820
824
}
821
825
}
822
826
@@ -1522,7 +1526,7 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
1522
1526
fn from ( slice : & [ T ] ) -> Box < [ T ] > {
1523
1527
let len = slice. len ( ) ;
1524
1528
// 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) ;
1526
1530
unsafe {
1527
1531
ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , buf. ptr ( ) , len) ;
1528
1532
buf. into_box ( slice. len ( ) ) . assume_init ( )
@@ -1687,12 +1691,13 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
1687
1691
1688
1692
#[ cfg( not( no_global_oom_handling) ) ]
1689
1693
#[ 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 > >
1691
1696
for Box < [ T ; N ] >
1692
1697
where
1693
- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
1698
+ [ ( ) ; { meta_num_slots_global ! ( CO_ALLOC_PREF ) } ] : ,
1694
1699
{
1695
- type Error = Vec < T , Global , COOP_PREFERRED > ;
1700
+ type Error = Vec < T , Global , CO_ALLOC_PREF > ;
1696
1701
1697
1702
/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
1698
1703
///
@@ -1712,7 +1717,7 @@ where
1712
1717
/// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
1713
1718
/// assert_eq!(state.len(), 100);
1714
1719
/// ```
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 > {
1716
1721
if vec. len ( ) == N {
1717
1722
let boxed_slice = vec. into_boxed_slice ( ) ;
1718
1723
Ok ( unsafe { boxed_slice_as_array_unchecked ( boxed_slice) } )
@@ -2049,14 +2054,15 @@ impl<I> FromIterator<I> for Box<[I]> {
2049
2054
2050
2055
#[ cfg( not( no_global_oom_handling) ) ]
2051
2056
#[ stable( feature = "box_slice_clone" , since = "1.3.0" ) ]
2057
+ #[ allow( unused_braces) ]
2052
2058
impl < T : Clone , A : Allocator + Clone > Clone for Box < [ T ] , A >
2053
2059
where
2054
- [ ( ) ; core :: alloc :: co_alloc_metadata_num_slots_with_preference :: < A > ( false ) ] : ,
2060
+ [ ( ) ; { crate :: meta_num_slots! ( A , crate :: CO_ALLOC_PREF_META_NO ! ( ) ) } ] : ,
2055
2061
{
2056
2062
fn clone ( & self ) -> Self {
2057
2063
let alloc = Box :: allocator ( self ) . clone ( ) ;
2058
2064
// 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 ( )
2060
2066
}
2061
2067
2062
2068
fn clone_from ( & mut self , other : & Self ) {
0 commit comments