Skip to content

Commit

Permalink
Stabilize slice_first_last_chunk
Browse files Browse the repository at this point in the history
This stabilizes all methods under `slice_first_last_chunk`.

Additionally, it const stabilizes the non-mut functions and moves the `_mut`
functions under `const_slice_first_last_chunk`. These are blocked on
`const_mut_refs`.

As part of this change, `slice_split_at_unchecked` was marked const-stable for
internal use (but not fully stable).
  • Loading branch information
tgross35 committed Jan 10, 2024
1 parent 01337bf commit 500d6f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(ptr_sub_ptr)]
#![feature(slice_first_last_chunk)]
#![cfg_attr(test, feature(test))]
#![allow(rustc::internal)]
#![deny(rustc::untranslatable_diagnostic)]
Expand Down
54 changes: 20 additions & 34 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let u = [10, 40, 30];
/// assert_eq!(Some(&[10, 40]), u.first_chunk::<2>());
///
Expand All @@ -338,9 +336,9 @@ impl<T> [T] {
/// let w: &[i32] = &[];
/// assert_eq!(Some(&[]), w.first_chunk::<0>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]> {
if self.len() < N {
None
Expand All @@ -358,8 +356,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &mut [0, 1, 2];
///
/// if let Some(first) = x.first_chunk_mut::<2>() {
Expand All @@ -370,9 +366,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.first_chunk_mut::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
pub const fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> {
if self.len() < N {
None
Expand All @@ -391,8 +387,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &[0, 1, 2];
///
/// if let Some((first, elements)) = x.split_first_chunk::<2>() {
Expand All @@ -402,9 +396,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.split_first_chunk::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])> {
if self.len() < N {
None
Expand All @@ -426,8 +420,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &mut [0, 1, 2];
///
/// if let Some((first, elements)) = x.split_first_chunk_mut::<2>() {
Expand All @@ -439,9 +431,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.split_first_chunk_mut::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
pub const fn split_first_chunk_mut<const N: usize>(
&mut self,
) -> Option<(&mut [T; N], &mut [T])> {
Expand All @@ -465,8 +457,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &[0, 1, 2];
///
/// if let Some((elements, last)) = x.split_last_chunk::<2>() {
Expand All @@ -476,9 +466,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.split_last_chunk::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])> {
if self.len() < N {
None
Expand All @@ -500,8 +490,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &mut [0, 1, 2];
///
/// if let Some((elements, last)) = x.split_last_chunk_mut::<2>() {
Expand All @@ -513,9 +501,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.split_last_chunk_mut::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
pub const fn split_last_chunk_mut<const N: usize>(
&mut self,
) -> Option<(&mut [T], &mut [T; N])> {
Expand All @@ -539,8 +527,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let u = [10, 40, 30];
/// assert_eq!(Some(&[40, 30]), u.last_chunk::<2>());
///
Expand All @@ -550,9 +536,9 @@ impl<T> [T] {
/// let w: &[i32] = &[];
/// assert_eq!(Some(&[]), w.last_chunk::<0>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]> {
if self.len() < N {
None
Expand All @@ -574,8 +560,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_first_last_chunk)]
///
/// let x = &mut [0, 1, 2];
///
/// if let Some(last) = x.last_chunk_mut::<2>() {
Expand All @@ -586,9 +570,9 @@ impl<T> [T] {
///
/// assert_eq!(None, x.last_chunk_mut::<4>());
/// ```
#[unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[rustc_const_unstable(feature = "slice_first_last_chunk", issue = "111774")]
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> {
if self.len() < N {
None
Expand Down Expand Up @@ -1885,7 +1869,6 @@ impl<T> [T] {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_slice_split_at_not_mut", since = "1.71.0")]
#[rustc_allow_const_fn_unstable(slice_split_at_unchecked)]
#[inline]
#[track_caller]
#[must_use]
Expand Down Expand Up @@ -1972,7 +1955,10 @@ impl<T> [T] {
/// }
/// ```
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
#[rustc_const_unstable(feature = "slice_split_at_unchecked", issue = "76014")]
#[rustc_const_stable(
feature = "const_slice_split_at_unchecked",
since = "CURRENT_RUSTC_VERSION"
)]
#[inline]
#[must_use]
pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
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 @@ -46,7 +46,6 @@
#![feature(pattern)]
#![feature(sort_internals)]
#![feature(slice_take)]
#![feature(slice_first_last_chunk)]
#![feature(slice_from_ptr_range)]
#![feature(slice_split_once)]
#![feature(split_as_slice)]
Expand Down

0 comments on commit 500d6f6

Please sign in to comment.