From 1acb44f03cd82c15c66f43abcc4b396378a0cc5d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 12:36:33 +0200 Subject: Use IntoIterator for array impl everywhere. --- compiler/rustc_ast_lowering/src/lib.rs | 7 +++---- compiler/rustc_codegen_cranelift/scripts/cargo.rs | 4 ++-- compiler/rustc_expand/src/proc_macro_server.rs | 5 ++--- compiler/rustc_hir/src/def.rs | 6 +++--- compiler/rustc_session/src/filesearch.rs | 4 ++-- compiler/rustc_session/src/session.rs | 5 ++--- compiler/rustc_target/src/lib.rs | 4 ++-- compiler/rustc_target/src/spec/mod.rs | 6 +++--- compiler/rustc_trait_selection/src/traits/object_safety.rs | 8 ++------ compiler/rustc_typeck/src/astconv/mod.rs | 3 +-- compiler/rustc_typeck/src/check/wfcheck.rs | 2 +- 11 files changed, 23 insertions(+), 31 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1a4f0a26f2b..d0fbc2d0f11 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -70,10 +70,9 @@ use smallvec::SmallVec; use tracing::{debug, trace}; macro_rules! arena_vec { - ($this:expr; $($x:expr),*) => ({ - let a = [$($x),*]; - $this.arena.alloc_from_iter(std::array::IntoIter::new(a)) - }); + ($this:expr; $($x:expr),*) => ( + $this.arena.alloc_from_iter([$($x),*]) + ); } mod asm; diff --git a/compiler/rustc_codegen_cranelift/scripts/cargo.rs b/compiler/rustc_codegen_cranelift/scripts/cargo.rs index 89ec8da77d3..41d82b581cd 100644 --- a/compiler/rustc_codegen_cranelift/scripts/cargo.rs +++ b/compiler/rustc_codegen_cranelift/scripts/cargo.rs @@ -42,7 +42,7 @@ fn main() { "RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", ); - std::array::IntoIter::new(["rustc".to_string()]) + IntoIterator::into_iter(["rustc".to_string()]) .chain(env::args().skip(2)) .chain([ "--".to_string(), @@ -56,7 +56,7 @@ fn main() { "RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", ); - std::array::IntoIter::new(["rustc".to_string()]) + IntoIterator::into_iter(["rustc".to_string()]) .chain(env::args().skip(2)) .chain([ "--".to_string(), diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index fa9e98be9e8..b7e47e4da6f 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -466,13 +466,12 @@ impl server::TokenStream for Rustc<'_, '_> { ast::ExprKind::Unary(ast::UnOp::Neg, e) => match &e.kind { ast::ExprKind::Lit(l) => match l.token { token::Lit { kind: token::Integer | token::Float, .. } => { - Ok(std::array::IntoIter::new([ + Ok(Self::TokenStream::from_iter([ // FIXME: The span of the `-` token is lost when // parsing, so we cannot faithfully recover it here. tokenstream::TokenTree::token(token::BinOp(token::Minus), e.span), tokenstream::TokenTree::token(token::Literal(l.token), l.span), - ]) - .collect()) + ])) } _ => Err(()), }, diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 60761a05de8..405aaf1f4e5 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -443,11 +443,11 @@ impl PerNS { } pub fn into_iter(self) -> IntoIter { - IntoIter::new([self.value_ns, self.type_ns, self.macro_ns]) + [self.value_ns, self.type_ns, self.macro_ns].into_iter() } pub fn iter(&self) -> IntoIter<&T, 3> { - IntoIter::new([&self.value_ns, &self.type_ns, &self.macro_ns]) + [&self.value_ns, &self.type_ns, &self.macro_ns].into_iter() } } @@ -481,7 +481,7 @@ impl PerNS> { /// Returns an iterator over the items which are `Some`. pub fn present_items(self) -> impl Iterator { - IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).flatten() + [self.type_ns, self.value_ns, self.macro_ns].into_iter().flatten() } } diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 9359a55e55a..357190178ce 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -4,6 +4,7 @@ pub use self::FileMatch::*; use std::env; use std::fs; +use std::iter::FromIterator; use std::path::{Path, PathBuf}; use crate::search_paths::{PathKind, SearchPath, SearchPathFile}; @@ -91,8 +92,7 @@ impl<'a> FileSearch<'a> { pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { let rustlib_path = rustc_target::target_rustlib_path(sysroot, target_triple); - std::array::IntoIter::new([sysroot, Path::new(&rustlib_path), Path::new("lib")]) - .collect::() + PathBuf::from_iter([sysroot, Path::new(&rustlib_path), Path::new("lib")]) } /// This function checks if sysroot is found using env::args().next(), and if it diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 54109559a3b..cef1d920d8f 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -795,12 +795,11 @@ impl Session { /// Returns a list of directories where target-specific tool binaries are located. pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec { let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple()); - let p = std::array::IntoIter::new([ + let p = PathBuf::from_iter([ Path::new(&self.sysroot), Path::new(&rustlib_path), Path::new("bin"), - ]) - .collect::(); + ]); if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] } } diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index 23d5d575d94..b18d17c1b7d 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -16,6 +16,7 @@ #![feature(min_specialization)] #![feature(step_trait)] +use std::iter::FromIterator; use std::path::{Path, PathBuf}; #[macro_use] @@ -47,12 +48,11 @@ const RUST_LIB_DIR: &str = "rustlib"; /// `"lib*/rustlib/x86_64-unknown-linux-gnu"`. pub fn target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf { let libdir = find_libdir(sysroot); - std::array::IntoIter::new([ + PathBuf::from_iter([ Path::new(libdir.as_ref()), Path::new(RUST_LIB_DIR), Path::new(target_triple), ]) - .collect::() } /// The name of the directory rustc expects libraries to be located. diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 0d49c7f6ee8..72d9b501545 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -42,6 +42,7 @@ use rustc_serialize::json::{Json, ToJson}; use rustc_span::symbol::{sym, Symbol}; use std::collections::BTreeMap; use std::convert::TryFrom; +use std::iter::FromIterator; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -2173,12 +2174,11 @@ impl Target { // Additionally look in the sysroot under `lib/rustlib//target.json` // as a fallback. let rustlib_path = crate::target_rustlib_path(&sysroot, &target_triple); - let p = std::array::IntoIter::new([ + let p = PathBuf::from_iter([ Path::new(sysroot), Path::new(&rustlib_path), Path::new("target.json"), - ]) - .collect::(); + ]); if p.is_file() { return load_file(&p); } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index afc546540d2..2ad8dc82a84 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -25,7 +25,6 @@ use rustc_span::symbol::Symbol; use rustc_span::{MultiSpan, Span}; use smallvec::SmallVec; -use std::array; use std::iter; use std::ops::ControlFlow; @@ -692,11 +691,8 @@ fn receiver_is_dispatchable<'tcx>( .to_predicate(tcx) }; - let caller_bounds: Vec> = param_env - .caller_bounds() - .iter() - .chain(array::IntoIter::new([unsize_predicate, trait_predicate])) - .collect(); + let caller_bounds: Vec> = + param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]).collect(); ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal()) }; diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index da751f20753..08261fedd4a 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -35,7 +35,6 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::wf::object_region_bounds; use smallvec::SmallVec; -use std::array; use std::collections::BTreeSet; use std::slice; @@ -1635,7 +1634,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2); let is_equality = is_equality(); - let bounds = array::IntoIter::new([bound, bound2]).chain(matching_candidates); + let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates); let mut err = if is_equality.is_some() { // More specific Error Index entry. struct_span_err!( diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 33a0c3275ca..1fc88829c77 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1822,7 +1822,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Inherent impl: take implied bounds from the `self` type. let self_ty = self.tcx.type_of(impl_def_id); let self_ty = self.normalize_associated_types_in(span, self_ty); - std::array::IntoIter::new([self_ty]).collect() + FxHashSet::from_iter([self_ty]) } } } -- cgit 1.4.1-3-g733a5