Skip to content

Commit

Permalink
Rollup merge of rust-lang#103522 - Dylan-DPC:76118/array-methods-stab…
Browse files Browse the repository at this point in the history
…, r=dtolnay

stabilise array methods

Closes rust-lang#76118

Stabilises the remaining array methods

FCP is yet to be carried out for this

There wasn't a clear consensus on the naming, but all the other alternatives had some flaws as discussed in the tracking issue and there was a silence on this issue for a year
  • Loading branch information
matthiaskrgr committed Jan 26, 2024
2 parents e7bbe8c + 2326f42 commit 94723d4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 10 deletions.
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
#![feature(allocator_api)]
#![feature(array_chunks)]
#![feature(array_into_iter_constructors)]
#![feature(array_methods)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(assert_matches)]
Expand Down
9 changes: 2 additions & 7 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ impl<T, const N: usize> [T; N] {
/// # Example
///
/// ```
/// #![feature(array_methods)]
///
/// let floats = [3.1, 2.7, -1.0];
/// let float_refs: [&f64; 3] = floats.each_ref();
/// assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
Expand All @@ -571,16 +569,14 @@ impl<T, const N: usize> [T; N] {
/// array if its elements are not [`Copy`].
///
/// ```
/// #![feature(array_methods)]
///
/// let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
/// let is_ascii = strings.each_ref().map(|s| s.is_ascii());
/// assert_eq!(is_ascii, [true, false, true]);
///
/// // We can still access the original array: it has not been moved.
/// assert_eq!(strings.len(), 3);
/// ```
#[unstable(feature = "array_methods", issue = "76118")]
#[stable(feature = "array_methods", since = "CURRENT_RUSTC_VERSION")]
pub fn each_ref(&self) -> [&T; N] {
from_trusted_iterator(self.iter())
}
Expand All @@ -592,15 +588,14 @@ impl<T, const N: usize> [T; N] {
/// # Example
///
/// ```
/// #![feature(array_methods)]
///
/// let mut floats = [3.1, 2.7, -1.0];
/// let float_refs: [&mut f64; 3] = floats.each_mut();
/// *float_refs[0] = 0.0;
/// assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
/// assert_eq!(floats, [0.0, 2.7, -1.0]);
/// ```
#[unstable(feature = "array_methods", issue = "76118")]
#[stable(feature = "array_methods", since = "CURRENT_RUSTC_VERSION")]
pub fn each_mut(&mut self) -> [&mut T; N] {
from_trusted_iterator(self.iter_mut())
}
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(alloc_layout_extra)]
#![feature(array_chunks)]
#![feature(array_methods)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(ascii_char_variants)]
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
html_playground_url = "https://play.rust-lang.org/"
)]
#![feature(rustc_private)]
#![feature(array_methods)]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
Expand Down

0 comments on commit 94723d4

Please sign in to comment.