Skip to content

Commit 9c0e8e0

Browse files
Fixing A and COOP_PREFERRED generics. WIP.
1 parent 16c897e commit 9c0e8e0

File tree

7 files changed

+31
-28
lines changed

7 files changed

+31
-28
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,11 +2799,11 @@ where
27992799
}
28002800

28012801
#[stable(feature = "rust1", since = "1.0.0")]
2802-
impl<T, A: Allocator, const COOP_PREFERRED: bool> FromIterator<T> for VecDeque<T, A, COOP_PREFERRED>
2802+
impl<T, const COOP_PREFERRED: bool> FromIterator<T> for VecDeque<T, Global, COOP_PREFERRED>
28032803
where
2804-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
2804+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
28052805
{
2806-
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> VecDeque<T, A, COOP_PREFERRED> {
2806+
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> VecDeque<T, Global, COOP_PREFERRED> {
28072807
SpecFromIter::spec_from_iter(iter.into_iter())
28082808
}
28092809
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
use super::{IntoIter, VecDeque};
2-
use crate::alloc::Allocator;
2+
use crate::Global;
33
use core::alloc;
44

55
/// Specialization trait used for `VecDeque::from_iter`
66
pub(super) trait SpecFromIter<T, I> {
77
fn spec_from_iter(iter: I) -> Self;
88
}
99

10-
impl<T, I, A: Allocator, const COOP_PREFERRED: bool> SpecFromIter<T, I>
11-
for VecDeque<T, A, COOP_PREFERRED>
10+
impl<T, I, const COOP_PREFERRED: bool> SpecFromIter<T, I>
11+
for VecDeque<T, Global, COOP_PREFERRED>
1212
where
1313
I: Iterator<Item = T>,
14-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
14+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
1515
{
1616
default fn spec_from_iter(iterator: I) -> Self {
1717
// Since converting is O(1) now, just re-use the `Vec` logic for
1818
// anything where we can't do something extra-special for `VecDeque`,
1919
// especially as that could save us some monomorphiziation work
2020
// if one uses the same iterators (like slice ones) with both.
21-
crate::vec::Vec::<T, A, COOP_PREFERRED>::from_iter(iterator).into()
21+
crate::vec::Vec::<T, Global, COOP_PREFERRED>::from_iter(iterator).into()
2222
}
2323
}
2424

25-
impl<T, A: Allocator, const COOP_PREFERRED: bool> SpecFromIter<T, crate::vec::IntoIter<T, A, COOP_PREFERRED>>
26-
for VecDeque<T, A, COOP_PREFERRED>
25+
impl<T, const COOP_PREFERRED: bool> SpecFromIter<T, crate::vec::IntoIter<T, Global, COOP_PREFERRED>>
26+
for VecDeque<T, Global, COOP_PREFERRED>
2727
where
28-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
28+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
2929
{
3030
#[inline]
31-
fn spec_from_iter(iterator: crate::vec::IntoIter<T, A, COOP_PREFERRED>) -> Self {
31+
fn spec_from_iter(iterator: crate::vec::IntoIter<T, Global, COOP_PREFERRED>) -> Self {
3232
iterator.into_vecdeque()
3333
}
3434
}
3535

36-
impl<T, A: Allocator, const COOP_PREFERRED: bool> SpecFromIter<T, IntoIter<T, A, COOP_PREFERRED>>
37-
for VecDeque<T, A, COOP_PREFERRED>
36+
impl<T, const COOP_PREFERRED: bool> SpecFromIter<T, IntoIter<T, Global, COOP_PREFERRED>>
37+
for VecDeque<T, Global, COOP_PREFERRED>
3838
where
39-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
39+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
4040
{
4141
#[inline]
42-
fn spec_from_iter(iterator: IntoIter<T, A, COOP_PREFERRED>) -> Self {
42+
fn spec_from_iter(iterator: IntoIter<T, Global, COOP_PREFERRED>) -> Self {
4343
iterator.into_vecdeque()
4444
}
4545
}

library/alloc/src/vec/in_place_collect.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
//! }
138138
//! vec.truncate(write_idx);
139139
//! ```
140-
use core::alloc::{self, Allocator};
140+
use core::alloc;
141+
use crate::alloc::Global;
141142
use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
142143
use core::mem::{self, ManuallyDrop, SizedTypeProperties};
143144
use core::ptr::{self};
@@ -152,10 +153,10 @@ pub(super) trait InPlaceIterableMarker {}
152153
impl<T> InPlaceIterableMarker for T where T: InPlaceIterable {}
153154

154155
#[allow(unused_braces)]
155-
impl<T, I, A: Allocator, const COOP_PREFERRED: bool> SpecFromIter<T, I> for Vec<T, A, COOP_PREFERRED>
156+
impl<T, I, const COOP_PREFERRED: bool> SpecFromIter<T, I> for Vec<T, Global, COOP_PREFERRED>
156157
where
157158
I: Iterator<Item = T> + SourceIter<Source: AsVecIntoIter> + InPlaceIterableMarker,
158-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
159+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
159160

160161
{
161162
default fn from_iter(mut iterator: I) -> Self {

library/alloc/src/vec/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ where
421421
{
422422
#[cfg(not(test))]
423423
fn clone(&self) -> Self {
424-
self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter()
424+
self.as_slice().to_vec_in::<A, COOP_PREFERRED>(self.alloc.deref().clone()).into_iter()
425425
}
426426
#[cfg(test)]
427427
fn clone(&self) -> Self {

library/alloc/src/vec/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,12 +2879,12 @@ where
28792879
#[cfg(not(no_global_oom_handling))]
28802880
#[stable(feature = "rust1", since = "1.0.0")]
28812881
#[allow(unused_braces)]
2882-
impl<T, A: Allocator, const COOP_PREFERRED: bool> FromIterator<T> for Vec<T, A, COOP_PREFERRED>
2882+
impl<T, const COOP_PREFERRED: bool> FromIterator<T> for Vec<T, Global, COOP_PREFERRED>
28832883
where
2884-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
2884+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
28852885
{
28862886
#[inline]
2887-
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T, A, COOP_PREFERRED> {
2887+
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T, Global, COOP_PREFERRED> {
28882888
<Self as SpecFromIter<T, I::IntoIter>>::from_iter(iter.into_iter())
28892889
}
28902890
}

library/alloc/src/vec/spec_from_iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::alloc::{self, Allocator};
1+
use core::alloc;
22
use crate::alloc::Global;
33
use core::mem::ManuallyDrop;
44
use core::ptr::{self};
@@ -28,10 +28,10 @@ pub(super) trait SpecFromIter<T, I> {
2828
}
2929

3030
#[allow(unused_braces)]
31-
impl<T, I, A: Allocator, const COOP_PREFERRED: bool> SpecFromIter<T, I> for Vec<T, A, COOP_PREFERRED>
31+
impl<T, I, const COOP_PREFERRED: bool> SpecFromIter<T, I> for Vec<T, Global, COOP_PREFERRED>
3232
where
3333
I: Iterator<Item = T>,
34-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
34+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
3535
{
3636
default fn from_iter(iterator: I) -> Self {
3737
SpecFromIterNested::from_iter(iterator)

library/alloc/src/vec/spec_from_iter_nested.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::alloc;
12
use core::cmp;
23
use core::iter::TrustedLen;
34
use core::ptr;
@@ -16,9 +17,10 @@ pub(super) trait SpecFromIterNested<T, I> {
1617
}
1718

1819
#[allow(unused_braces)]
19-
impl<T, I> SpecFromIterNested<T, I> for Vec<T, Global, {DEFAULT_COOP_PREFERRED!()}>
20+
impl<T, I, const COOP_PREFERRED: bool> SpecFromIterNested<T, I> for Vec<T, Global, COOP_PREFERRED>
2021
where
2122
I: Iterator<Item = T>,
23+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
2224
{
2325
default fn from_iter(mut iterator: I) -> Self {
2426
// Unroll the first iteration, as the vector is going to be
@@ -43,7 +45,7 @@ where
4345
};
4446
// must delegate to spec_extend() since extend() itself delegates
4547
// to spec_from for empty Vecs
46-
<Vec<T> as SpecExtend<T, I>>::spec_extend(&mut vector, iterator);
48+
<Vec<T, Global, COOP_PREFERRED> as SpecExtend<T, I>>::spec_extend(&mut vector, iterator);
4749
vector
4850
}
4951
}

0 commit comments

Comments
 (0)