Stabilize by-value [T; N] iterator core::array::IntoIter

Tracking issue: https://github.com/rust-lang/rust/issues/65798

This is unblocked now that `min_const_generics` has been stabilized
in https://github.com/rust-lang/rust/pull/79135.

This PR does *not* include the corresponding `IntoIterator` impl,
which is https://github.com/rust-lang/rust/pull/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.
This commit is contained in:
Simon Sapin 2020-12-29 09:16:46 +01:00
parent 6c523a7a0e
commit 61c49d4042
11 changed files with 9 additions and 18 deletions

View File

@ -11,11 +11,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(no_crate_inject, attr(deny(warnings))) test(no_crate_inject, attr(deny(warnings)))
)] )]
#![feature(array_value_iter_slice)]
#![feature(dropck_eyepatch)] #![feature(dropck_eyepatch)]
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(maybe_uninit_slice)] #![feature(maybe_uninit_slice)]
#![feature(array_value_iter)]
#![cfg_attr(bootstrap, feature(min_const_generics))] #![cfg_attr(bootstrap, feature(min_const_generics))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(test))]

View File

@ -30,7 +30,6 @@
//! get confused if the spans from leaf AST nodes occur in multiple places //! get confused if the spans from leaf AST nodes occur in multiple places
//! in the HIR, especially for multiple identifiers. //! in the HIR, especially for multiple identifiers.
#![feature(array_value_iter)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(or_patterns)] #![feature(or_patterns)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View File

@ -2,7 +2,6 @@
//! //!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
#![feature(array_value_iter)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(const_fn)] // For the unsizing cast on `&[]` #![feature(const_fn)] // For the unsizing cast on `&[]`
#![feature(const_panic)] #![feature(const_panic)]

View File

@ -11,7 +11,6 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(drain_filter)] #![feature(drain_filter)]

View File

@ -56,7 +56,6 @@ This API is completely unstable and subject to change.
*/ */
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]

View File

@ -79,7 +79,6 @@
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(array_chunks)] #![feature(array_chunks)]
#![feature(array_methods)] #![feature(array_methods)]
#![feature(array_value_iter)]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(allow_internal_unstable)] #![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)] #![feature(arbitrary_self_types)]

View File

@ -11,7 +11,7 @@ use crate::{
/// A by-value [array] iterator. /// A by-value [array] iterator.
/// ///
/// [array]: ../../std/primitive.array.html /// [array]: ../../std/primitive.array.html
#[unstable(feature = "array_value_iter", issue = "65798")] #[stable(feature = "array_value_iter", since = "1.51.0")]
pub struct IntoIter<T, const N: usize> { pub struct IntoIter<T, const N: usize> {
/// This is the array we are iterating over. /// This is the array we are iterating over.
/// ///
@ -38,10 +38,11 @@ pub struct IntoIter<T, const N: usize> {
impl<T, const N: usize> IntoIter<T, N> { impl<T, const N: usize> IntoIter<T, N> {
/// Creates a new iterator over the given `array`. /// Creates a new iterator over the given `array`.
/// ///
/// *Note*: this method might never get stabilized and/or removed in the /// *Note*: this method might be deprecated in the future,
/// future as there will likely be another, preferred way of obtaining this /// after [`IntoIterator` is implemented for arrays][array-into-iter].
/// iterator (either via `IntoIterator` for arrays or via another way). ///
#[unstable(feature = "array_value_iter", issue = "65798")] /// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
#[stable(feature = "array_value_iter", since = "1.51.0")]
pub fn new(array: [T; N]) -> Self { pub fn new(array: [T; N]) -> Self {
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit` // SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`
// promise: // promise:
@ -69,7 +70,7 @@ impl<T, const N: usize> IntoIter<T, N> {
/// Returns an immutable slice of all elements that have not been yielded /// Returns an immutable slice of all elements that have not been yielded
/// yet. /// yet.
#[unstable(feature = "array_value_iter_slice", issue = "65798")] #[stable(feature = "array_value_iter", since = "1.51.0")]
pub fn as_slice(&self) -> &[T] { pub fn as_slice(&self) -> &[T] {
// SAFETY: We know that all elements within `alive` are properly initialized. // SAFETY: We know that all elements within `alive` are properly initialized.
unsafe { unsafe {
@ -79,7 +80,7 @@ impl<T, const N: usize> IntoIter<T, N> {
} }
/// Returns a mutable slice of all elements that have not been yielded yet. /// Returns a mutable slice of all elements that have not been yielded yet.
#[unstable(feature = "array_value_iter_slice", issue = "65798")] #[stable(feature = "array_value_iter", since = "1.51.0")]
pub fn as_mut_slice(&mut self) -> &mut [T] { pub fn as_mut_slice(&mut self) -> &mut [T] {
// SAFETY: We know that all elements within `alive` are properly initialized. // SAFETY: We know that all elements within `alive` are properly initialized.
unsafe { unsafe {

View File

@ -17,7 +17,7 @@ use crate::slice::{Iter, IterMut};
mod iter; mod iter;
#[unstable(feature = "array_value_iter", issue = "65798")] #[stable(feature = "array_value_iter", since = "1.51.0")]
pub use iter::IntoIter; pub use iter::IntoIter;
/// Converts a reference to `T` into a reference to an array of length 1 (without copying). /// Converts a reference to `T` into a reference to an array of length 1 (without copying).

View File

@ -45,7 +45,6 @@
#![feature(slice_internals)] #![feature(slice_internals)]
#![feature(slice_partition_dedup)] #![feature(slice_partition_dedup)]
#![feature(int_error_matching)] #![feature(int_error_matching)]
#![feature(array_value_iter)]
#![feature(iter_advance_by)] #![feature(iter_advance_by)]
#![feature(iter_partition_in_place)] #![feature(iter_partition_in_place)]
#![feature(iter_is_partitioned)] #![feature(iter_is_partitioned)]

View File

@ -1,6 +1,5 @@
// check-pass // check-pass
#![feature(array_value_iter)]
#![feature(trusted_len)] #![feature(trusted_len)]
use std::{ use std::{

View File

@ -1,6 +1,5 @@
// check-pass // check-pass
#![feature(array_value_iter)]
#![feature(trusted_len)] #![feature(trusted_len)]
use std::{ use std::{