Skip to content

Commit fbbab29

Browse files
Rollup merge of rust-lang#80470 - SimonSapin:array-intoiter-type, r=m-ou-se
Stabilize by-value `[T; N]` iterator `core::array::IntoIter` Tracking issue: rust-lang#65798 This is unblocked now that `min_const_generics` has been stabilized in rust-lang#79135. This PR does *not* include the corresponding `IntoIterator` impl, which is rust-lang#65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2 parents 38f073b + 83a7c59 commit fbbab29

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#![feature(allocator_api)]
7979
#![feature(array_chunks)]
8080
#![feature(array_methods)]
81-
#![feature(array_value_iter)]
8281
#![feature(array_windows)]
8382
#![feature(allow_internal_unstable)]
8483
#![feature(arbitrary_self_types)]

core/src/array/iter.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
/// A by-value [array] iterator.
1212
///
1313
/// [array]: ../../std/primitive.array.html
14-
#[unstable(feature = "array_value_iter", issue = "65798")]
14+
#[stable(feature = "array_value_iter", since = "1.51.0")]
1515
pub struct IntoIter<T, const N: usize> {
1616
/// This is the array we are iterating over.
1717
///
@@ -38,10 +38,21 @@ pub struct IntoIter<T, const N: usize> {
3838
impl<T, const N: usize> IntoIter<T, N> {
3939
/// Creates a new iterator over the given `array`.
4040
///
41-
/// *Note*: this method might never get stabilized and/or removed in the
42-
/// future as there will likely be another, preferred way of obtaining this
43-
/// iterator (either via `IntoIterator` for arrays or via another way).
44-
#[unstable(feature = "array_value_iter", issue = "65798")]
41+
/// *Note*: this method might be deprecated in the future,
42+
/// after [`IntoIterator` is implemented for arrays][array-into-iter].
43+
///
44+
/// # Examples
45+
///
46+
/// ```
47+
/// use std::array;
48+
///
49+
/// for value in array::IntoIter::new([1, 2, 3, 4, 5]) {
50+
/// // The type of `value` is a `i32` here, instead of `&i32`
51+
/// let _: i32 = value;
52+
/// }
53+
/// ```
54+
/// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
55+
#[stable(feature = "array_value_iter", since = "1.51.0")]
4556
pub fn new(array: [T; N]) -> Self {
4657
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`
4758
// promise:
@@ -69,7 +80,7 @@ impl<T, const N: usize> IntoIter<T, N> {
6980

7081
/// Returns an immutable slice of all elements that have not been yielded
7182
/// yet.
72-
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
83+
#[stable(feature = "array_value_iter", since = "1.51.0")]
7384
pub fn as_slice(&self) -> &[T] {
7485
// SAFETY: We know that all elements within `alive` are properly initialized.
7586
unsafe {
@@ -79,7 +90,7 @@ impl<T, const N: usize> IntoIter<T, N> {
7990
}
8091

8192
/// Returns a mutable slice of all elements that have not been yielded yet.
82-
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
93+
#[stable(feature = "array_value_iter", since = "1.51.0")]
8394
pub fn as_mut_slice(&mut self) -> &mut [T] {
8495
// SAFETY: We know that all elements within `alive` are properly initialized.
8596
unsafe {

core/src/array/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::slice::{Iter, IterMut};
1818

1919
mod iter;
2020

21-
#[unstable(feature = "array_value_iter", issue = "65798")]
21+
#[stable(feature = "array_value_iter", since = "1.51.0")]
2222
pub use iter::IntoIter;
2323

2424
/// Converts a reference to `T` into a reference to an array of length 1 (without copying).

core/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#![feature(slice_internals)]
5151
#![feature(slice_partition_dedup)]
5252
#![feature(int_error_matching)]
53-
#![feature(array_value_iter)]
5453
#![feature(iter_advance_by)]
5554
#![feature(iter_partition_in_place)]
5655
#![feature(iter_intersperse)]

0 commit comments

Comments
 (0)