Skip to content

Commit

Permalink
Rollup merge of rust-lang#125171 - scottmcm:rename-flatten, r=jhpratt
Browse files Browse the repository at this point in the history
Rename `flatten(_mut)` → `as_flattened(_mut)`

As requested by libs-api in rust-lang#95629 (comment)

(This is just the rename, not the stabilization, so can land without waiting on the FCP in that other issue.)
  • Loading branch information
matthiaskrgr authored May 17, 2024
2 parents e62688e + facc0bb commit 7a8d222
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4533,21 +4533,21 @@ impl<T, const N: usize> [[T; N]] {
/// ```
/// #![feature(slice_flatten)]
///
/// assert_eq!([[1, 2, 3], [4, 5, 6]].flatten(), &[1, 2, 3, 4, 5, 6]);
/// assert_eq!([[1, 2, 3], [4, 5, 6]].as_flattened(), &[1, 2, 3, 4, 5, 6]);
///
/// assert_eq!(
/// [[1, 2, 3], [4, 5, 6]].flatten(),
/// [[1, 2], [3, 4], [5, 6]].flatten(),
/// [[1, 2, 3], [4, 5, 6]].as_flattened(),
/// [[1, 2], [3, 4], [5, 6]].as_flattened(),
/// );
///
/// let slice_of_empty_arrays: &[[i32; 0]] = &[[], [], [], [], []];
/// assert!(slice_of_empty_arrays.flatten().is_empty());
/// assert!(slice_of_empty_arrays.as_flattened().is_empty());
///
/// let empty_slice_of_arrays: &[[u32; 10]] = &[];
/// assert!(empty_slice_of_arrays.flatten().is_empty());
/// assert!(empty_slice_of_arrays.as_flattened().is_empty());
/// ```
#[unstable(feature = "slice_flatten", issue = "95629")]
pub const fn flatten(&self) -> &[T] {
pub const fn as_flattened(&self) -> &[T] {
let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
} else {
Expand Down Expand Up @@ -4581,11 +4581,11 @@ impl<T, const N: usize> [[T; N]] {
/// }
///
/// let mut array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
/// add_5_to_all(array.flatten_mut());
/// add_5_to_all(array.as_flattened_mut());
/// assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]);
/// ```
#[unstable(feature = "slice_flatten", issue = "95629")]
pub fn flatten_mut(&mut self) -> &mut [T] {
pub fn as_flattened_mut(&mut self) -> &mut [T] {
let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
} else {
Expand Down
4 changes: 2 additions & 2 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,14 +2609,14 @@ fn test_slice_from_ptr_range() {
#[should_panic = "slice len overflow"]
fn test_flatten_size_overflow() {
let x = &[[(); usize::MAX]; 2][..];
let _ = x.flatten();
let _ = x.as_flattened();
}

#[test]
#[should_panic = "slice len overflow"]
fn test_flatten_mut_size_overflow() {
let x = &mut [[(); usize::MAX]; 2][..];
let _ = x.flatten_mut();
let _ = x.as_flattened_mut();
}

#[test]
Expand Down

0 comments on commit 7a8d222

Please sign in to comment.