Skip to content

Commit 1acb44f

Browse files
committed
Use IntoIterator for array impl everywhere.
1 parent b34cf1a commit 1acb44f

File tree

21 files changed

+41
-50
lines changed

21 files changed

+41
-50
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ use smallvec::SmallVec;
7070
use tracing::{debug, trace};
7171

7272
macro_rules! arena_vec {
73-
($this:expr; $($x:expr),*) => ({
74-
let a = [$($x),*];
75-
$this.arena.alloc_from_iter(std::array::IntoIter::new(a))
76-
});
73+
($this:expr; $($x:expr),*) => (
74+
$this.arena.alloc_from_iter([$($x),*])
75+
);
7776
}
7877

7978
mod asm;

compiler/rustc_codegen_cranelift/scripts/cargo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() {
4242
"RUSTFLAGS",
4343
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
4444
);
45-
std::array::IntoIter::new(["rustc".to_string()])
45+
IntoIterator::into_iter(["rustc".to_string()])
4646
.chain(env::args().skip(2))
4747
.chain([
4848
"--".to_string(),
@@ -56,7 +56,7 @@ fn main() {
5656
"RUSTFLAGS",
5757
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
5858
);
59-
std::array::IntoIter::new(["rustc".to_string()])
59+
IntoIterator::into_iter(["rustc".to_string()])
6060
.chain(env::args().skip(2))
6161
.chain([
6262
"--".to_string(),

compiler/rustc_expand/src/proc_macro_server.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,12 @@ impl server::TokenStream for Rustc<'_, '_> {
466466
ast::ExprKind::Unary(ast::UnOp::Neg, e) => match &e.kind {
467467
ast::ExprKind::Lit(l) => match l.token {
468468
token::Lit { kind: token::Integer | token::Float, .. } => {
469-
Ok(std::array::IntoIter::new([
469+
Ok(Self::TokenStream::from_iter([
470470
// FIXME: The span of the `-` token is lost when
471471
// parsing, so we cannot faithfully recover it here.
472472
tokenstream::TokenTree::token(token::BinOp(token::Minus), e.span),
473473
tokenstream::TokenTree::token(token::Literal(l.token), l.span),
474-
])
475-
.collect())
474+
]))
476475
}
477476
_ => Err(()),
478477
},

compiler/rustc_hir/src/def.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ impl<T> PerNS<T> {
443443
}
444444

445445
pub fn into_iter(self) -> IntoIter<T, 3> {
446-
IntoIter::new([self.value_ns, self.type_ns, self.macro_ns])
446+
[self.value_ns, self.type_ns, self.macro_ns].into_iter()
447447
}
448448

449449
pub fn iter(&self) -> IntoIter<&T, 3> {
450-
IntoIter::new([&self.value_ns, &self.type_ns, &self.macro_ns])
450+
[&self.value_ns, &self.type_ns, &self.macro_ns].into_iter()
451451
}
452452
}
453453

@@ -481,7 +481,7 @@ impl<T> PerNS<Option<T>> {
481481

482482
/// Returns an iterator over the items which are `Some`.
483483
pub fn present_items(self) -> impl Iterator<Item = T> {
484-
IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).flatten()
484+
[self.type_ns, self.value_ns, self.macro_ns].into_iter().flatten()
485485
}
486486
}
487487

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub use self::FileMatch::*;
44

55
use std::env;
66
use std::fs;
7+
use std::iter::FromIterator;
78
use std::path::{Path, PathBuf};
89

910
use crate::search_paths::{PathKind, SearchPath, SearchPathFile};
@@ -91,8 +92,7 @@ impl<'a> FileSearch<'a> {
9192

9293
pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
9394
let rustlib_path = rustc_target::target_rustlib_path(sysroot, target_triple);
94-
std::array::IntoIter::new([sysroot, Path::new(&rustlib_path), Path::new("lib")])
95-
.collect::<PathBuf>()
95+
PathBuf::from_iter([sysroot, Path::new(&rustlib_path), Path::new("lib")])
9696
}
9797

9898
/// This function checks if sysroot is found using env::args().next(), and if it

compiler/rustc_session/src/session.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,11 @@ impl Session {
795795
/// Returns a list of directories where target-specific tool binaries are located.
796796
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
797797
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple());
798-
let p = std::array::IntoIter::new([
798+
let p = PathBuf::from_iter([
799799
Path::new(&self.sysroot),
800800
Path::new(&rustlib_path),
801801
Path::new("bin"),
802-
])
803-
.collect::<PathBuf>();
802+
]);
804803
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
805804
}
806805

compiler/rustc_target/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(min_specialization)]
1717
#![feature(step_trait)]
1818

19+
use std::iter::FromIterator;
1920
use std::path::{Path, PathBuf};
2021

2122
#[macro_use]
@@ -47,12 +48,11 @@ const RUST_LIB_DIR: &str = "rustlib";
4748
/// `"lib*/rustlib/x86_64-unknown-linux-gnu"`.
4849
pub fn target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
4950
let libdir = find_libdir(sysroot);
50-
std::array::IntoIter::new([
51+
PathBuf::from_iter([
5152
Path::new(libdir.as_ref()),
5253
Path::new(RUST_LIB_DIR),
5354
Path::new(target_triple),
5455
])
55-
.collect::<PathBuf>()
5656
}
5757

5858
/// The name of the directory rustc expects libraries to be located.

compiler/rustc_target/src/spec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc_serialize::json::{Json, ToJson};
4242
use rustc_span::symbol::{sym, Symbol};
4343
use std::collections::BTreeMap;
4444
use std::convert::TryFrom;
45+
use std::iter::FromIterator;
4546
use std::ops::{Deref, DerefMut};
4647
use std::path::{Path, PathBuf};
4748
use std::str::FromStr;
@@ -2173,12 +2174,11 @@ impl Target {
21732174
// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
21742175
// as a fallback.
21752176
let rustlib_path = crate::target_rustlib_path(&sysroot, &target_triple);
2176-
let p = std::array::IntoIter::new([
2177+
let p = PathBuf::from_iter([
21772178
Path::new(sysroot),
21782179
Path::new(&rustlib_path),
21792180
Path::new("target.json"),
2180-
])
2181-
.collect::<PathBuf>();
2181+
]);
21822182
if p.is_file() {
21832183
return load_file(&p);
21842184
}

compiler/rustc_trait_selection/src/traits/object_safety.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_span::symbol::Symbol;
2525
use rustc_span::{MultiSpan, Span};
2626
use smallvec::SmallVec;
2727

28-
use std::array;
2928
use std::iter;
3029
use std::ops::ControlFlow;
3130

@@ -692,11 +691,8 @@ fn receiver_is_dispatchable<'tcx>(
692691
.to_predicate(tcx)
693692
};
694693

695-
let caller_bounds: Vec<Predicate<'tcx>> = param_env
696-
.caller_bounds()
697-
.iter()
698-
.chain(array::IntoIter::new([unsize_predicate, trait_predicate]))
699-
.collect();
694+
let caller_bounds: Vec<Predicate<'tcx>> =
695+
param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]).collect();
700696

701697
ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal())
702698
};

compiler/rustc_typeck/src/astconv/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
3535
use rustc_trait_selection::traits::wf::object_region_bounds;
3636

3737
use smallvec::SmallVec;
38-
use std::array;
3938
use std::collections::BTreeSet;
4039
use std::slice;
4140

@@ -1635,7 +1634,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16351634
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
16361635

16371636
let is_equality = is_equality();
1638-
let bounds = array::IntoIter::new([bound, bound2]).chain(matching_candidates);
1637+
let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates);
16391638
let mut err = if is_equality.is_some() {
16401639
// More specific Error Index entry.
16411640
struct_span_err!(

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18221822
// Inherent impl: take implied bounds from the `self` type.
18231823
let self_ty = self.tcx.type_of(impl_def_id);
18241824
let self_ty = self.normalize_associated_types_in(span, self_ty);
1825-
std::array::IntoIter::new([self_ty]).collect()
1825+
FxHashSet::from_iter([self_ty])
18261826
}
18271827
}
18281828
}

library/alloc/src/collections/binary_heap.rs

+1-1
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

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

+4-4
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

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

+1-1
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
}

library/alloc/src/collections/linked_list.rs

+1-1
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

library/core/tests/iter/adapters/flatten.rs

+5-6
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

library/std/src/collections/hash/map.rs

+1-1
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

library/std/src/collections/hash/set.rs

+1-1
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

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ impl Build {
10431043
options[1] = Some(format!("-Clink-arg=-Wl,{}", threads));
10441044
}
10451045

1046-
std::array::IntoIter::new(options).flatten()
1046+
IntoIterator::into_iter(options).flatten()
10471047
}
10481048

10491049
/// Returns if this target should statically link the C runtime, if specified

src/test/ui/proc-macro/auxiliary/custom-quote.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![crate_type = "proc-macro"]
77

88
extern crate proc_macro;
9+
use std::iter::FromIterator;
910
use std::str::FromStr;
1011
use proc_macro::*;
1112

@@ -23,7 +24,7 @@ pub fn custom_quote(input: TokenStream) -> TokenStream {
2324
let set_span_method = TokenStream::from_str("ident.set_span").unwrap();
2425
let set_span_arg = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, quoted_span)));
2526
let suffix = TokenStream::from_str(";proc_macro::TokenStream::from(proc_macro::TokenTree::Ident(ident))").unwrap();
26-
let full_stream: TokenStream = std::array::IntoIter::new([prefix, set_span_method, set_span_arg, suffix]).collect();
27+
let full_stream = TokenStream::from_iter([prefix, set_span_method, set_span_arg, suffix]);
2728
full_stream
2829
}
2930
_ => unreachable!()

src/tools/clippy/clippy_lints/src/matches.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use clippy_utils::{
1313
remove_blocks, strip_pat_refs,
1414
};
1515
use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash};
16-
use core::array;
1716
use core::iter::{once, ExactSizeIterator};
1817
use if_chain::if_chain;
1918
use rustc_ast::ast::{Attribute, LitKind};
@@ -1306,7 +1305,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
13061305
return find_matches_sugg(
13071306
cx,
13081307
let_expr,
1309-
array::IntoIter::new([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]),
1308+
IntoIterator::into_iter([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]),
13101309
expr,
13111310
true,
13121311
);

0 commit comments

Comments
 (0)