From 06398554bf580d25daa66f8b0cbaed011daf8e29 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sat, 24 Jan 2026 21:27:26 +0300 Subject: [PATCH] Stabilize `str_as_str` --- 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 2926248edbf55..4ff25fd611efa 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -36,7 +36,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 3e1eeba4e92e6..2fb803c200509 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -5126,7 +5126,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 } @@ -5137,7 +5138,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 ab7389a1300c5..1ad29bd84db1a 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -3121,7 +3121,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 4e4d377ae2708..f253367d07b35 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 25bd7005b9942..07dd904aa7279 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3221,7 +3221,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 }