From 911ee9403e1778ebac01b5f2d45ab9d960d5da4a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 11:31:09 +0200 Subject: [PATCH 1/5] Deprecate array::IntoIter::new. --- library/core/src/array/iter.rs | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 5d63cf03fcb..80ba1c95a1d 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -36,27 +36,8 @@ pub struct IntoIter { impl IntoIter { /// Creates a new iterator over the given `array`. - /// - /// *Note*: this method might be deprecated in the future, - /// since [`IntoIterator`] is now implemented for arrays. - /// - /// # Examples - /// - /// ``` - /// use std::array; - /// - /// for value in array::IntoIter::new([1, 2, 3, 4, 5]) { - /// // The type of `value` is an `i32` here, instead of `&i32` - /// let _: i32 = value; - /// } - /// - /// // Since Rust 1.53, arrays implement IntoIterator directly: - /// for value in [1, 2, 3, 4, 5] { - /// // The type of `value` is an `i32` here, instead of `&i32` - /// let _: i32 = value; - /// } - /// ``` #[stable(feature = "array_value_iter", since = "1.51.0")] + #[rustc_deprecated(since = "1.57.0", reason = "use `IntoIterator::into_iter` instead")] pub fn new(array: [T; N]) -> Self { // SAFETY: The transmute here is actually safe. The docs of `MaybeUninit` // promise: From b34cf1a9e176e3ca525638e9075696d8467596ba Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 11:44:36 +0200 Subject: [PATCH 2/5] Swap body of array::IntoIter::new and IntoIterator::new. --- library/core/src/array/iter.rs | 35 +++++++++++++++++++++++++++------- library/core/src/array/mod.rs | 21 -------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 80ba1c95a1d..01ccf12a71a 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -34,11 +34,23 @@ pub struct IntoIter { alive: Range, } -impl IntoIter { - /// Creates a new iterator over the given `array`. - #[stable(feature = "array_value_iter", since = "1.51.0")] - #[rustc_deprecated(since = "1.57.0", reason = "use `IntoIterator::into_iter` instead")] - pub fn new(array: [T; N]) -> Self { +// Note: the `#[rustc_skip_array_during_method_dispatch]` on `trait IntoIterator` +// hides this implementation from explicit `.into_iter()` calls on editions < 2021, +// so those calls will still resolve to the slice implementation, by reference. +#[stable(feature = "array_into_iter_impl", since = "1.53.0")] +impl IntoIterator for [T; N] { + type Item = T; + type IntoIter = IntoIter; + + /// Creates a consuming iterator, that is, one that moves each value out of + /// the array (from start to end). The array cannot be used after calling + /// this unless `T` implements `Copy`, so the whole array is copied. + /// + /// Arrays have special behavior when calling `.into_iter()` prior to the + /// 2021 edition -- see the [array] Editions section for more information. + /// + /// [array]: prim@array + fn into_iter(self) -> Self::IntoIter { // SAFETY: The transmute here is actually safe. The docs of `MaybeUninit` // promise: // @@ -57,11 +69,20 @@ impl IntoIter { // Until then, we can use `mem::transmute_copy` to create a bitwise copy // as a different type, then forget `array` so that it is not dropped. unsafe { - let iter = Self { data: mem::transmute_copy(&array), alive: 0..N }; - mem::forget(array); + let iter = IntoIter { data: mem::transmute_copy(&self), alive: 0..N }; + mem::forget(self); iter } } +} + +impl IntoIter { + /// Creates a new iterator over the given `array`. + #[stable(feature = "array_value_iter", since = "1.51.0")] + #[rustc_deprecated(since = "1.57.0", reason = "use `IntoIterator::into_iter` instead")] + pub fn new(array: [T; N]) -> Self { + IntoIterator::into_iter(array) + } /// Returns an immutable slice of all elements that have not been yielded /// yet. diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index d635829151e..23fd1453e54 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -243,27 +243,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -// Note: the `#[rustc_skip_array_during_method_dispatch]` on `trait IntoIterator` -// hides this implementation from explicit `.into_iter()` calls on editions < 2021, -// so those calls will still resolve to the slice implementation, by reference. -#[stable(feature = "array_into_iter_impl", since = "1.53.0")] -impl IntoIterator for [T; N] { - type Item = T; - type IntoIter = IntoIter; - - /// Creates a consuming iterator, that is, one that moves each value out of - /// the array (from start to end). The array cannot be used after calling - /// this unless `T` implements `Copy`, so the whole array is copied. - /// - /// Arrays have special behavior when calling `.into_iter()` prior to the - /// 2021 edition -- see the [array] Editions section for more information. - /// - /// [array]: prim@array - fn into_iter(self) -> Self::IntoIter { - IntoIter::new(self) - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, const N: usize> IntoIterator for &'a [T; N] { type Item = &'a T; From 1acb44f03cd82c15c66f43abcc4b396378a0cc5d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 12:36:33 +0200 Subject: [PATCH 3/5] 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 +++--- .../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 +- library/alloc/src/collections/binary_heap.rs | 2 +- library/alloc/src/collections/btree/map.rs | 8 ++++---- library/alloc/src/collections/btree/set.rs | 2 +- library/alloc/src/collections/linked_list.rs | 2 +- library/core/tests/iter/adapters/flatten.rs | 11 +++++------ library/std/src/collections/hash/map.rs | 2 +- library/std/src/collections/hash/set.rs | 2 +- src/bootstrap/lib.rs | 2 +- src/test/ui/proc-macro/auxiliary/custom-quote.rs | 3 ++- src/tools/clippy/clippy_lints/src/matches.rs | 3 +-- 21 files changed, 41 insertions(+), 50 deletions(-) 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 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 @@ fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result 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 @@ pub fn map U>(self, mut f: F) -> 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 @@ pub fn is_empty(&self) -> bool { /// 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 @@ 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 @@ pub fn search_path_dirs(&self) -> Vec { 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 @@ pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> { /// 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 @@ pub trait HashStableContext {} /// `"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_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 @@ fn load_file(path: &Path) -> Result<(Target, TargetWarnings), String> { // 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::{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::wf::object_region_bounds; use smallvec::SmallVec; -use std::array; use std::collections::BTreeSet; use std::slice; @@ -1635,7 +1634,7 @@ fn one_bound_for_assoc_type( 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 @@ pub(super) fn impl_implied_bounds( // 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]) } } } diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 7d87974b47e..76fbfa9fc59 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -1500,7 +1500,7 @@ fn from(vec: Vec) -> BinaryHeap { /// } /// ``` fn from(arr: [T; N]) -> Self { - core::array::IntoIter::new(arr).collect() + Self::from_iter(arr) } } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 2ff7b0fbb75..3bd5b8ddf08 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -1305,11 +1305,11 @@ pub fn into_values(self) -> IntoValues { pub(crate) fn bulk_build_from_sorted_iter(iter: I) -> Self where K: Ord, - I: Iterator, + I: IntoIterator, { let mut root = Root::new(); let mut length = 0; - root.bulk_push(DedupSortedIter::new(iter), &mut length); + root.bulk_push(DedupSortedIter::new(iter.into_iter()), &mut length); BTreeMap { root: Some(root), length } } } @@ -1944,7 +1944,7 @@ fn from_iter>(iter: T) -> BTreeMap { // use stable sort to preserve the insertion order. inputs.sort_by(|a, b| a.0.cmp(&b.0)); - BTreeMap::bulk_build_from_sorted_iter(inputs.into_iter()) + BTreeMap::bulk_build_from_sorted_iter(inputs) } } @@ -2061,7 +2061,7 @@ fn index(&self, key: &Q) -> &V { // use stable sort to preserve the insertion order. arr.sort_by(|a, b| a.0.cmp(&b.0)); - BTreeMap::bulk_build_from_sorted_iter(core::array::IntoIter::new(arr)) + BTreeMap::bulk_build_from_sorted_iter(arr) } } diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 0322cabccde..4a83cdb917c 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1106,7 +1106,7 @@ fn from_iter>(iter: I) -> BTreeSet { // use stable sort to preserve the insertion order. arr.sort(); - let iter = core::array::IntoIter::new(arr).map(|k| (k, ())); + let iter = IntoIterator::into_iter(arr).map(|k| (k, ())); let map = BTreeMap::bulk_build_from_sorted_iter(iter); BTreeSet { map } } diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index e4913b16adb..c8aad4877e9 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1961,7 +1961,7 @@ fn hash(&self, state: &mut H) { /// assert_eq!(list1, list2); /// ``` fn from(arr: [T; N]) -> Self { - core::array::IntoIter::new(arr).collect() + Self::from_iter(arr) } } diff --git a/library/core/tests/iter/adapters/flatten.rs b/library/core/tests/iter/adapters/flatten.rs index cd6513327f0..f8ab8c9d444 100644 --- a/library/core/tests/iter/adapters/flatten.rs +++ b/library/core/tests/iter/adapters/flatten.rs @@ -1,5 +1,4 @@ use super::*; -use core::array; use core::iter::*; #[test] @@ -134,7 +133,7 @@ fn test_double_ended_flatten() { #[test] fn test_trusted_len_flatten() { fn assert_trusted_len(_: &T) {} - let mut iter = array::IntoIter::new([[0; 3]; 4]).flatten(); + let mut iter = IntoIterator::into_iter([[0; 3]; 4]).flatten(); assert_trusted_len(&iter); assert_eq!(iter.size_hint(), (12, Some(12))); @@ -143,21 +142,21 @@ fn assert_trusted_len(_: &T) {} iter.next_back(); assert_eq!(iter.size_hint(), (10, Some(10))); - let iter = array::IntoIter::new([[(); usize::MAX]; 1]).flatten(); + let iter = IntoIterator::into_iter([[(); usize::MAX]; 1]).flatten(); assert_eq!(iter.size_hint(), (usize::MAX, Some(usize::MAX))); - let iter = array::IntoIter::new([[(); usize::MAX]; 2]).flatten(); + let iter = IntoIterator::into_iter([[(); usize::MAX]; 2]).flatten(); assert_eq!(iter.size_hint(), (usize::MAX, None)); let mut a = [(); 10]; let mut b = [(); 10]; - let iter = array::IntoIter::new([&mut a, &mut b]).flatten(); + let iter = IntoIterator::into_iter([&mut a, &mut b]).flatten(); assert_trusted_len(&iter); assert_eq!(iter.size_hint(), (20, Some(20))); core::mem::drop(iter); - let iter = array::IntoIter::new([&a, &b]).flatten(); + let iter = IntoIterator::into_iter([&a, &b]).flatten(); assert_trusted_len(&iter); assert_eq!(iter.size_hint(), (20, Some(20))); diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 12246b5173d..ce34e235f5d 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1186,7 +1186,7 @@ fn index(&self, key: &Q) -> &V { /// assert_eq!(map1, map2); /// ``` fn from(arr: [(K, V); N]) -> Self { - crate::array::IntoIter::new(arr).collect() + Self::from_iter(arr) } } diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 1fc1d39b181..3f264ee6732 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -1022,7 +1022,7 @@ fn from_iter>(iter: I) -> HashSet { /// assert_eq!(set1, set2); /// ``` fn from(arr: [T; N]) -> Self { - crate::array::IntoIter::new(arr).collect() + Self::from_iter(arr) } } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 1667dfc3f85..82462f9758e 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1043,7 +1043,7 @@ fn lld_flags(&self, target: TargetSelection) -> impl Iterator { options[1] = Some(format!("-Clink-arg=-Wl,{}", threads)); } - std::array::IntoIter::new(options).flatten() + IntoIterator::into_iter(options).flatten() } /// Returns if this target should statically link the C runtime, if specified diff --git a/src/test/ui/proc-macro/auxiliary/custom-quote.rs b/src/test/ui/proc-macro/auxiliary/custom-quote.rs index 714417deee5..3b7811748ed 100644 --- a/src/test/ui/proc-macro/auxiliary/custom-quote.rs +++ b/src/test/ui/proc-macro/auxiliary/custom-quote.rs @@ -6,6 +6,7 @@ #![crate_type = "proc-macro"] extern crate proc_macro; +use std::iter::FromIterator; use std::str::FromStr; use proc_macro::*; @@ -23,7 +24,7 @@ pub fn custom_quote(input: TokenStream) -> TokenStream { let set_span_method = TokenStream::from_str("ident.set_span").unwrap(); let set_span_arg = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, quoted_span))); let suffix = TokenStream::from_str(";proc_macro::TokenStream::from(proc_macro::TokenTree::Ident(ident))").unwrap(); - let full_stream: TokenStream = std::array::IntoIter::new([prefix, set_span_method, set_span_arg, suffix]).collect(); + let full_stream = TokenStream::from_iter([prefix, set_span_method, set_span_arg, suffix]); full_stream } _ => unreachable!() diff --git a/src/tools/clippy/clippy_lints/src/matches.rs b/src/tools/clippy/clippy_lints/src/matches.rs index 7142df98c3f..48e459e0165 100644 --- a/src/tools/clippy/clippy_lints/src/matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches.rs @@ -13,7 +13,6 @@ remove_blocks, strip_pat_refs, }; use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; -use core::array; use core::iter::{once, ExactSizeIterator}; use if_chain::if_chain; use rustc_ast::ast::{Attribute, LitKind}; @@ -1306,7 +1305,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) return find_matches_sugg( cx, let_expr, - array::IntoIter::new([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]), + IntoIterator::into_iter([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]), expr, true, ); From eb3fc45c87a008c1f362492da0a8e21dfce18e9f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 12:37:03 +0200 Subject: [PATCH 4/5] Update docs. --- library/core/src/primitive_docs.rs | 3 +-- library/std/src/primitive_docs.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index f47a30c9b5d..8fcd8cdeb10 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -606,8 +606,7 @@ mod prim_pointer {} /// println!("array[{}] = {}", i, x); /// } /// -/// // You can explicitly iterate an array by value using -/// // `IntoIterator::into_iter` or `std::array::IntoIter::new`: +/// // You can explicitly iterate an array by value using `IntoIterator::into_iter` /// for item in IntoIterator::into_iter(array).enumerate() { /// let (i, x): (usize, i32) = item; /// println!("array[{}] = {}", i, x); diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index f47a30c9b5d..8fcd8cdeb10 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -606,8 +606,7 @@ mod prim_pointer {} /// println!("array[{}] = {}", i, x); /// } /// -/// // You can explicitly iterate an array by value using -/// // `IntoIterator::into_iter` or `std::array::IntoIter::new`: +/// // You can explicitly iterate an array by value using `IntoIterator::into_iter` /// for item in IntoIterator::into_iter(array).enumerate() { /// let (i, x): (usize, i32) = item; /// println!("array[{}] = {}", i, x); From 27d39357b7052d96e1b3903518841d14534c38cf Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 4 Dec 2021 19:42:37 +0100 Subject: [PATCH 5/5] Update array::IntoIter::new deprecation version. --- library/core/src/array/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 01ccf12a71a..fe7b3576e2f 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -79,7 +79,7 @@ fn into_iter(self) -> Self::IntoIter { impl IntoIter { /// Creates a new iterator over the given `array`. #[stable(feature = "array_value_iter", since = "1.51.0")] - #[rustc_deprecated(since = "1.57.0", reason = "use `IntoIterator::into_iter` instead")] + #[rustc_deprecated(since = "1.59.0", reason = "use `IntoIterator::into_iter` instead")] pub fn new(array: [T; N]) -> Self { IntoIterator::into_iter(array) }