Skip to content

Commit da53497

Browse files
committed
Use IntoIterator for array impl everywhere.
1 parent d36aab0 commit da53497

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

alloc/src/collections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> {
15001500
/// }
15011501
/// ```
15021502
fn from(arr: [T; N]) -> Self {
1503-
core::array::IntoIter::new(arr).collect()
1503+
Self::from_iter(arr)
15041504
}
15051505
}
15061506

alloc/src/collections/btree/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,11 @@ impl<K, V> BTreeMap<K, V> {
13051305
pub(crate) fn bulk_build_from_sorted_iter<I>(iter: I) -> Self
13061306
where
13071307
K: Ord,
1308-
I: Iterator<Item = (K, V)>,
1308+
I: IntoIterator<Item = (K, V)>,
13091309
{
13101310
let mut root = Root::new();
13111311
let mut length = 0;
1312-
root.bulk_push(DedupSortedIter::new(iter), &mut length);
1312+
root.bulk_push(DedupSortedIter::new(iter.into_iter()), &mut length);
13131313
BTreeMap { root: Some(root), length }
13141314
}
13151315
}
@@ -1944,7 +1944,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
19441944

19451945
// use stable sort to preserve the insertion order.
19461946
inputs.sort_by(|a, b| a.0.cmp(&b.0));
1947-
BTreeMap::bulk_build_from_sorted_iter(inputs.into_iter())
1947+
BTreeMap::bulk_build_from_sorted_iter(inputs)
19481948
}
19491949
}
19501950

@@ -2061,7 +2061,7 @@ impl<K: Ord, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V> {
20612061

20622062
// use stable sort to preserve the insertion order.
20632063
arr.sort_by(|a, b| a.0.cmp(&b.0));
2064-
BTreeMap::bulk_build_from_sorted_iter(core::array::IntoIter::new(arr))
2064+
BTreeMap::bulk_build_from_sorted_iter(arr)
20652065
}
20662066
}
20672067

alloc/src/collections/btree/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
11061106

11071107
// use stable sort to preserve the insertion order.
11081108
arr.sort();
1109-
let iter = core::array::IntoIter::new(arr).map(|k| (k, ()));
1109+
let iter = IntoIterator::into_iter(arr).map(|k| (k, ()));
11101110
let map = BTreeMap::bulk_build_from_sorted_iter(iter);
11111111
BTreeSet { map }
11121112
}

alloc/src/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ impl<T, const N: usize> From<[T; N]> for LinkedList<T> {
19611961
/// assert_eq!(list1, list2);
19621962
/// ```
19631963
fn from(arr: [T; N]) -> Self {
1964-
core::array::IntoIter::new(arr).collect()
1964+
Self::from_iter(arr)
19651965
}
19661966
}
19671967

core/tests/iter/adapters/flatten.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::*;
2-
use core::array;
32
use core::iter::*;
43

54
#[test]
@@ -134,7 +133,7 @@ fn test_double_ended_flatten() {
134133
#[test]
135134
fn test_trusted_len_flatten() {
136135
fn assert_trusted_len<T: TrustedLen>(_: &T) {}
137-
let mut iter = array::IntoIter::new([[0; 3]; 4]).flatten();
136+
let mut iter = IntoIterator::into_iter([[0; 3]; 4]).flatten();
138137
assert_trusted_len(&iter);
139138

140139
assert_eq!(iter.size_hint(), (12, Some(12)));
@@ -143,21 +142,21 @@ fn test_trusted_len_flatten() {
143142
iter.next_back();
144143
assert_eq!(iter.size_hint(), (10, Some(10)));
145144

146-
let iter = array::IntoIter::new([[(); usize::MAX]; 1]).flatten();
145+
let iter = IntoIterator::into_iter([[(); usize::MAX]; 1]).flatten();
147146
assert_eq!(iter.size_hint(), (usize::MAX, Some(usize::MAX)));
148147

149-
let iter = array::IntoIter::new([[(); usize::MAX]; 2]).flatten();
148+
let iter = IntoIterator::into_iter([[(); usize::MAX]; 2]).flatten();
150149
assert_eq!(iter.size_hint(), (usize::MAX, None));
151150

152151
let mut a = [(); 10];
153152
let mut b = [(); 10];
154153

155-
let iter = array::IntoIter::new([&mut a, &mut b]).flatten();
154+
let iter = IntoIterator::into_iter([&mut a, &mut b]).flatten();
156155
assert_trusted_len(&iter);
157156
assert_eq!(iter.size_hint(), (20, Some(20)));
158157
core::mem::drop(iter);
159158

160-
let iter = array::IntoIter::new([&a, &b]).flatten();
159+
let iter = IntoIterator::into_iter([&a, &b]).flatten();
161160
assert_trusted_len(&iter);
162161
assert_eq!(iter.size_hint(), (20, Some(20)));
163162

std/src/collections/hash/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ where
11861186
/// assert_eq!(map1, map2);
11871187
/// ```
11881188
fn from(arr: [(K, V); N]) -> Self {
1189-
crate::array::IntoIter::new(arr).collect()
1189+
Self::from_iter(arr)
11901190
}
11911191
}
11921192

std/src/collections/hash/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ where
10221022
/// assert_eq!(set1, set2);
10231023
/// ```
10241024
fn from(arr: [T; N]) -> Self {
1025-
crate::array::IntoIter::new(arr).collect()
1025+
Self::from_iter(arr)
10261026
}
10271027
}
10281028

0 commit comments

Comments
 (0)