Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize slice_flatten #125561

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,15 +2643,13 @@ impl<T, A: Allocator, const N: usize> Vec<[T; N], A> {
/// # Examples
///
/// ```
/// #![feature(slice_flatten)]
///
/// let mut vec = vec![[1, 2, 3], [4, 5, 6], [7, 8, 9]];
/// assert_eq!(vec.pop(), Some([7, 8, 9]));
///
/// let mut flattened = vec.into_flattened();
/// assert_eq!(flattened.pop(), Some(6));
/// ```
#[unstable(feature = "slice_flatten", issue = "95629")]
#[stable(feature = "slice_flatten", since = "CURRENT_RUSTC_VERSION")]
pub fn into_flattened(self) -> Vec<T, A> {
let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc();
let (new_len, new_cap) = if T::IS_ZST {
Expand Down
1 change: 0 additions & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#![feature(const_str_from_utf8)]
#![feature(panic_update_hook)]
#![feature(pointer_is_aligned_to)]
#![feature(slice_flatten)]
#![feature(thin_box)]
#![feature(strict_provenance)]
#![feature(drain_keep_rest)]
Expand Down
9 changes: 3 additions & 6 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4531,8 +4531,6 @@ impl<T, const N: usize> [[T; N]] {
/// # Examples
///
/// ```
/// #![feature(slice_flatten)]
///
/// assert_eq!([[1, 2, 3], [4, 5, 6]].as_flattened(), &[1, 2, 3, 4, 5, 6]);
///
/// assert_eq!(
Expand All @@ -4546,7 +4544,8 @@ impl<T, const N: usize> [[T; N]] {
/// let empty_slice_of_arrays: &[[u32; 10]] = &[];
/// assert!(empty_slice_of_arrays.as_flattened().is_empty());
/// ```
#[unstable(feature = "slice_flatten", issue = "95629")]
#[stable(feature = "slice_flatten", since = "CURRENT_RUSTC_VERSION")]
Cyborus04 marked this conversation as resolved.
Show resolved Hide resolved
#[rustc_const_unstable(feature = "const_slice_flatten", issue = "95629")]
pub const fn as_flattened(&self) -> &[T] {
let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
Expand All @@ -4572,8 +4571,6 @@ impl<T, const N: usize> [[T; N]] {
/// # Examples
///
/// ```
/// #![feature(slice_flatten)]
///
/// fn add_5_to_all(slice: &mut [i32]) {
/// for i in slice {
/// *i += 5;
Expand All @@ -4584,7 +4581,7 @@ impl<T, const N: usize> [[T; N]] {
/// 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")]
#[stable(feature = "slice_flatten", since = "CURRENT_RUSTC_VERSION")]
pub fn as_flattened_mut(&mut self) -> &mut [T] {
Comment on lines +4584 to 4585
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be const unstable as well? Even if there is no stable way to call it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's not const fn today. If you want to send a PR adding const and making it const-unstable, that would seem reasonable, though.

let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#![feature(const_array_from_ref)]
#![feature(const_slice_from_ref)]
#![feature(waker_getters)]
#![feature(slice_flatten)]
#![feature(error_generic_member_access)]
#![feature(error_in_core)]
#![feature(trait_upcasting)]
Expand Down
Loading