Const-stabilize str::is_char_boundary and str::split_at(_mut)(_checked).

This commit is contained in:
Zachary S 2024-11-13 16:24:37 -06:00
parent 9c707a8b76
commit 138327244f

View file

@ -185,7 +185,7 @@ impl str {
/// ```
#[must_use]
#[stable(feature = "is_char_boundary", since = "1.9.0")]
#[rustc_const_unstable(feature = "const_is_char_boundary", issue = "131516")]
#[rustc_const_stable(feature = "const_is_char_boundary", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn is_char_boundary(&self, index: usize) -> bool {
// 0 is always ok.
@ -642,7 +642,7 @@ impl str {
#[inline]
#[must_use]
#[stable(feature = "str_split_at", since = "1.4.0")]
#[rustc_const_unstable(feature = "const_str_split_at", issue = "131518")]
#[rustc_const_stable(feature = "const_str_split_at", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_at(&self, mid: usize) -> (&str, &str) {
match self.split_at_checked(mid) {
None => slice_error_fail(self, 0, mid),
@ -683,7 +683,7 @@ impl str {
#[inline]
#[must_use]
#[stable(feature = "str_split_at", since = "1.4.0")]
#[rustc_const_unstable(feature = "const_str_split_at", issue = "131518")]
#[rustc_const_stable(feature = "const_str_split_at", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(mid) {
@ -723,7 +723,7 @@ impl str {
#[inline]
#[must_use]
#[stable(feature = "split_at_checked", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_str_split_at", issue = "131518")]
#[rustc_const_stable(feature = "const_str_split_at", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_at_checked(&self, mid: usize) -> Option<(&str, &str)> {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(mid) {
@ -764,7 +764,7 @@ impl str {
#[inline]
#[must_use]
#[stable(feature = "split_at_checked", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_str_split_at", issue = "131518")]
#[rustc_const_stable(feature = "const_str_split_at", since = "CURRENT_RUSTC_VERSION")]
pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut str, &mut str)> {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(mid) {