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

core/slice: Mark some split_off variants unstably const #138540

Merged
merged 1 commit into from
Mar 20, 2025
Merged
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
26 changes: 18 additions & 8 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4446,8 +4446,10 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_take", since = "CURRENT_RUSTC_VERSION")]
pub fn split_off_first<'a>(self: &mut &'a Self) -> Option<&'a T> {
let (first, rem) = self.split_first()?;
#[rustc_const_unstable(feature = "const_split_off_first_last", issue = "138539")]
pub const fn split_off_first<'a>(self: &mut &'a Self) -> Option<&'a T> {
// FIXME(const-hack): Use `?` when available in const instead of `let-else`.
let Some((first, rem)) = self.split_first() else { return None };
*self = rem;
Some(first)
}
Expand All @@ -4469,8 +4471,11 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_take", since = "CURRENT_RUSTC_VERSION")]
pub fn split_off_first_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T> {
let (first, rem) = mem::take(self).split_first_mut()?;
#[rustc_const_unstable(feature = "const_split_off_first_last", issue = "138539")]
pub const fn split_off_first_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T> {
// FIXME(const-hack): Use `mem::take` and `?` when available in const.
// Original: `mem::take(self).split_first_mut()?`
let Some((first, rem)) = mem::replace(self, &mut []).split_first_mut() else { return None };
*self = rem;
Some(first)
}
Expand All @@ -4491,8 +4496,10 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_take", since = "CURRENT_RUSTC_VERSION")]
pub fn split_off_last<'a>(self: &mut &'a Self) -> Option<&'a T> {
let (last, rem) = self.split_last()?;
#[rustc_const_unstable(feature = "const_split_off_first_last", issue = "138539")]
pub const fn split_off_last<'a>(self: &mut &'a Self) -> Option<&'a T> {
// FIXME(const-hack): Use `?` when available in const instead of `let-else`.
let Some((last, rem)) = self.split_last() else { return None };
*self = rem;
Some(last)
}
Expand All @@ -4514,8 +4521,11 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_take", since = "CURRENT_RUSTC_VERSION")]
pub fn split_off_last_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T> {
let (last, rem) = mem::take(self).split_last_mut()?;
#[rustc_const_unstable(feature = "const_split_off_first_last", issue = "138539")]
pub const fn split_off_last_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T> {
// FIXME(const-hack): Use `mem::take` and `?` when available in const.
// Original: `mem::take(self).split_last_mut()?`
let Some((last, rem)) = mem::replace(self, &mut []).split_last_mut() else { return None };
*self = rem;
Some(last)
}
Expand Down
Loading