Skip to content

Commit 45518cd

Browse files
CoAlloc: Unspecialized and specialized Box<[T]>::from(Vec) and Vec::from(Box<[T>]), so it works with legacy code.
1 parent c427cd4 commit 45518cd

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,14 +3491,28 @@ where
34913491
}
34923492
}
34933493

3494-
// note: test pulls in std, which causes errors here
3494+
// @FIXME unsure about test
34953495
#[cfg(not(test))]
3496-
#[stable(feature = "vec_from_box", since = "1.18.0")]
3496+
#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here?
3497+
#[unstable(feature = "global_co_alloc", issue="none")]
34973498
#[allow(unused_braces)]
34983499
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> From<Box<[T], A>>
34993500
for Vec<T, A, CO_ALLOC_PREF>
35003501
where
35013502
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
3503+
{
3504+
default fn from(s: Box<[T], A>) -> Self {
3505+
s.into_vec_co()
3506+
}
3507+
}
3508+
3509+
#[cfg(not(test))]
3510+
#[stable(feature = "vec_from_box", since = "1.18.0")]
3511+
#[allow(unused_braces)]
3512+
impl<T, A: Allocator> From<Box<[T], A>>
3513+
for Vec<T, A, {CO_ALLOC_PREF_DEFAULT!()}>
3514+
where
3515+
[(); { crate::meta_num_slots_default!(A) }]:,
35023516
{
35033517
/// Convert a boxed slice into a vector by transferring ownership of
35043518
/// the existing heap allocation.
@@ -3510,19 +3524,34 @@ where
35103524
/// assert_eq!(Vec::from(b), vec![1, 2, 3]);
35113525
/// ```
35123526
fn from(s: Box<[T], A>) -> Self {
3513-
s.into_vec_co()
3527+
s.into_vec()
35143528
}
35153529
}
35163530

3517-
// note: test pulls in std, which causes errors here
35183531
#[cfg(not(no_global_oom_handling))]
3532+
// @FIXME Can this apply to test?
35193533
#[cfg(not(test))]
3520-
#[stable(feature = "box_from_vec", since = "1.20.0")]
3534+
#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here?
3535+
#[unstable(feature = "global_co_alloc", issue="none")]
35213536
#[allow(unused_braces)]
35223537
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> From<Vec<T, A, CO_ALLOC_PREF>>
35233538
for Box<[T], A>
35243539
where
35253540
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
3541+
{
3542+
default fn from(v: Vec<T, A, CO_ALLOC_PREF>) -> Self {
3543+
v.into_boxed_slice()
3544+
}
3545+
}
3546+
// note: test pulls in std, which causes errors here
3547+
#[cfg(not(no_global_oom_handling))]
3548+
#[cfg(not(test))]
3549+
#[stable(feature = "box_from_vec", since = "1.20.0")]
3550+
#[allow(unused_braces)]
3551+
impl<T, A: Allocator> From<Vec<T, A>>
3552+
for Box<[T], A>
3553+
where
3554+
[(); { crate::meta_num_slots_default!(A) }]:,
35263555
{
35273556
/// Convert a vector into a boxed slice.
35283557
///
@@ -3542,7 +3571,7 @@ where
35423571
///
35433572
/// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice());
35443573
/// ```
3545-
fn from(v: Vec<T, A, CO_ALLOC_PREF>) -> Self {
3574+
fn from(v: Vec<T, A>) -> Self {
35463575
v.into_boxed_slice()
35473576
}
35483577
}

0 commit comments

Comments
 (0)