From 911ee9403e1778ebac01b5f2d45ab9d960d5da4a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 11:31:09 +0200 Subject: Deprecate array::IntoIter::new. --- library/core/src/array/iter.rs | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'library/core/src/array') 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: -- cgit 1.4.1-3-g733a5 From b34cf1a9e176e3ca525638e9075696d8467596ba Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 11:44:36 +0200 Subject: 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(-) (limited to 'library/core/src/array') 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 @@ impl fmt::Debug for [T; N] { } } -// 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; -- cgit 1.4.1-3-g733a5 From 27d39357b7052d96e1b3903518841d14534c38cf Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 4 Dec 2021 19:42:37 +0100 Subject: Update array::IntoIter::new deprecation version. --- library/core/src/array/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'library/core/src/array') 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 @@ impl IntoIterator for [T; N] { 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) } -- cgit 1.4.1-3-g733a5