@@ -444,14 +444,7 @@ pub type DefVec<T, A = Global> =
444
444
#[ unstable( feature = "global_co_alloc_vec" , issue = "none" ) ]
445
445
pub type WeVec < T , const WEIGHT : u8 > = Vec < T , Global , { WEIGHT > 127 } > ;
446
446
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 > {
455
448
/// Constructs a new, empty `Vec<T>`.
456
449
///
457
450
/// The vector will not allocate until elements are pushed onto it.
@@ -467,6 +460,25 @@ where
467
460
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
468
461
#[ must_use]
469
462
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 {
470
482
Vec { buf : RawVec :: NEW , len : 0 }
471
483
}
472
484
@@ -3242,7 +3254,7 @@ where
3242
3254
///
3243
3255
/// The vector will not allocate until elements are pushed onto it.
3244
3256
fn default ( ) -> Vec < T , Global , COOP_PREFERRED > {
3245
- Vec :: new ( )
3257
+ Vec :: new_co ( )
3246
3258
}
3247
3259
}
3248
3260
0 commit comments