@@ -444,14 +444,7 @@ pub type DefVec<T, A = Global> =
444444#[ unstable( feature = "global_co_alloc_vec" , issue = "none" ) ]
445445pub type WeVec < T , const WEIGHT : u8 > = Vec < T , Global , { WEIGHT > 127 } > ;
446446
447- ////////////////////////////////////////////////////////////////////////////////
448- // Inherent methods
449- ////////////////////////////////////////////////////////////////////////////////
450-
451- impl < T , const COOP_PREFERRED : bool > Vec < T , Global , COOP_PREFERRED >
452- where
453- [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
454- {
447+ impl < T > Vec < T > {
455448 /// Constructs a new, empty `Vec<T>`.
456449 ///
457450 /// The vector will not allocate until elements are pushed onto it.
@@ -467,6 +460,25 @@ where
467460 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
468461 #[ must_use]
469462 pub const fn new ( ) -> Self {
463+ #[ allow( unused_braces) ]
464+ Vec :: < T , Global , { DEFAULT_COOP_PREFERRED ! ( ) } > :: new_co ( )
465+ }
466+ }
467+
468+ ////////////////////////////////////////////////////////////////////////////////
469+ // Inherent methods
470+ ////////////////////////////////////////////////////////////////////////////////
471+
472+ impl < T , const COOP_PREFERRED : bool > Vec < T , Global , COOP_PREFERRED >
473+ where
474+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
475+ {
476+ /// Like new(), but it respects COOP_PREFERRED.
477+ #[ inline]
478+ #[ rustc_const_stable( feature = "const_vec_new_co" , since = "1.60.0" ) ] //@FIXME This is `rustc_const_stable`, so that String::new() can be const and can call this.
479+ #[ unstable( feature = "vec_new_co" , reason = "confirm_or_fix_the_function_name" , issue = "none" ) ]
480+ #[ must_use]
481+ pub const fn new_co ( ) -> Self {
470482 Vec { buf : RawVec :: NEW , len : 0 }
471483 }
472484
@@ -3242,7 +3254,7 @@ where
32423254 ///
32433255 /// The vector will not allocate until elements are pushed onto it.
32443256 fn default ( ) -> Vec < T , Global , COOP_PREFERRED > {
3245- Vec :: new ( )
3257+ Vec :: new_co ( )
32463258 }
32473259}
32483260
0 commit comments