Skip to content

Commit a4bdfe2

Browse files
committed
Support allocators in various Default for IntoIter impls
Global implements Default so we can use that as bound for all allocators
1 parent 2b32b31 commit a4bdfe2

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

library/alloc/src/collections/btree/map.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ impl<K: Debug, V: Debug, A: Allocator + Clone> Debug for IntoIter<K, V, A> {
450450
}
451451

452452
#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")]
453-
impl<K, V> Default for IntoIter<K, V> {
453+
impl<K, V, A> Default for IntoIter<K, V, A>
454+
where
455+
A: Allocator + Default + Clone,
456+
{
454457
/// Creates an empty `btree_map::IntoIter`.
455458
///
456459
/// ```
@@ -459,7 +462,7 @@ impl<K, V> Default for IntoIter<K, V> {
459462
/// assert_eq!(iter.len(), 0);
460463
/// ```
461464
fn default() -> Self {
462-
IntoIter { range: Default::default(), length: 0, alloc: Global }
465+
IntoIter { range: Default::default(), length: 0, alloc: Default::default() }
463466
}
464467
}
465468

@@ -2106,7 +2109,10 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoKeys<K, V, A> {
21062109
impl<K, V, A: Allocator + Clone> FusedIterator for IntoKeys<K, V, A> {}
21072110

21082111
#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")]
2109-
impl<K, V> Default for IntoKeys<K, V> {
2112+
impl<K, V, A> Default for IntoKeys<K, V, A>
2113+
where
2114+
A: Allocator + Default + Clone,
2115+
{
21102116
/// Creates an empty `btree_map::IntoKeys`.
21112117
///
21122118
/// ```
@@ -2154,7 +2160,10 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoValues<K, V, A> {
21542160
impl<K, V, A: Allocator + Clone> FusedIterator for IntoValues<K, V, A> {}
21552161

21562162
#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")]
2157-
impl<K, V> Default for IntoValues<K, V> {
2163+
impl<K, V, A> Default for IntoValues<K, V, A>
2164+
where
2165+
A: Allocator + Default + Clone,
2166+
{
21582167
/// Creates an empty `btree_map::IntoValues`.
21592168
///
21602169
/// ```

library/alloc/src/collections/btree/set.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,10 @@ impl<T, A: Allocator + Clone> ExactSizeIterator for IntoIter<T, A> {
15761576
impl<T, A: Allocator + Clone> FusedIterator for IntoIter<T, A> {}
15771577

15781578
#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")]
1579-
impl<T> Default for IntoIter<T> {
1579+
impl<T, A> Default for IntoIter<T, A>
1580+
where
1581+
A: Allocator + Default + Clone,
1582+
{
15801583
/// Creates an empty `btree_set::IntoIter`.
15811584
///
15821585
/// ```

library/alloc/src/vec/into_iter.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {}
348348
unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}
349349

350350
#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")]
351-
impl<T> Default for IntoIter<T> {
351+
impl<T, A> Default for IntoIter<T, A>
352+
where
353+
A: Allocator + Default,
354+
{
352355
/// Creates an empty `vec::IntoIter`.
353356
///
354357
/// ```
@@ -358,7 +361,7 @@ impl<T> Default for IntoIter<T> {
358361
/// assert_eq!(iter.as_slice(), &[]);
359362
/// ```
360363
fn default() -> Self {
361-
super::Vec::new().into_iter()
364+
super::Vec::new_in(Default::default()).into_iter()
362365
}
363366
}
364367

0 commit comments

Comments
 (0)