From df3bedb88be1c3a7fe14d607788f4c85e55b2474 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sun, 22 Feb 2026 17:25:48 +0300 Subject: [PATCH] Revert "Revert "Stabilize `str_as_str`"" This reverts commit 9f0a41009648ac9065e22460ee9b3d0f21714a29. --- library/alloctests/tests/lib.rs | 1 - library/core/src/bstr/mod.rs | 2 -- library/core/src/ffi/c_str.rs | 3 ++- library/core/src/slice/mod.rs | 6 ++++-- library/core/src/str/mod.rs | 3 ++- library/std/src/ffi/os_str.rs | 3 ++- library/std/src/path.rs | 3 ++- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 699a5010282b0..f18d6e1bb3794 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -33,7 +33,6 @@ #![feature(thin_box)] #![feature(drain_keep_rest)] #![feature(local_waker)] -#![feature(str_as_str)] #![feature(strict_provenance_lints)] #![feature(string_replace_in_place)] #![feature(vec_deque_truncate_front)] diff --git a/library/core/src/bstr/mod.rs b/library/core/src/bstr/mod.rs index 34e1ea66c99ad..3e3b78b452e01 100644 --- a/library/core/src/bstr/mod.rs +++ b/library/core/src/bstr/mod.rs @@ -74,7 +74,6 @@ impl ByteStr { /// it helps dereferencing other "container" types, /// for example `Box` or `Arc`. #[inline] - // #[unstable(feature = "str_as_str", issue = "130366")] #[unstable(feature = "bstr", issue = "134915")] pub const fn as_byte_str(&self) -> &ByteStr { self @@ -86,7 +85,6 @@ impl ByteStr { /// it helps dereferencing other "container" types, /// for example `Box` or `MutexGuard`. #[inline] - // #[unstable(feature = "str_as_str", issue = "130366")] #[unstable(feature = "bstr", issue = "134915")] pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr { self diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 621277179bb38..8097066a57339 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -655,7 +655,8 @@ impl CStr { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_c_str(&self) -> &CStr { self } diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 36dd4d6782ac1..ac3088142f7df 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -5337,7 +5337,8 @@ impl [T] { /// it helps dereferencing other "container" types to slices, /// for example `Box<[T]>` or `Arc<[T]>`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_slice(&self) -> &[T] { self } @@ -5348,7 +5349,8 @@ impl [T] { /// it helps dereferencing other "container" types to slices, /// for example `Box<[T]>` or `MutexGuard<[T]>`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_mut_slice(&mut self) -> &mut [T] { self } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 98354643aa405..2d7fdb824d1f8 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -3137,7 +3137,8 @@ impl str { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_str(&self) -> &str { self } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index ca910153e5260..6b4cf3cea831c 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1285,7 +1285,8 @@ impl OsStr { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_os_str(&self) -> &OsStr { self } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index bf27df7b04281..712031ff7ccb1 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3235,7 +3235,8 @@ impl Path { /// it helps dereferencing other `PathBuf`-like types to `Path`s, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_path(&self) -> &Path { self }