Rollup merge of #145930 - GrigorenkoPV:const_str_as_str, r=joshtriplett

`const`ify (the unstable) `str::as_str`

Tracking issue: rust-lang/rust#130366

The method was not initially marked `const` presumably because it is only useful with `Deref`. But now that const traits seem to be a thing that can actually become real, why not make it `const`?

PR `const`ifying `Deref`: rust-lang/rust#145279
This commit is contained in:
Stuart Cook 2025-08-28 23:10:36 +10:00 committed by GitHub
commit f6c56bcd66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3072,7 +3072,7 @@ impl str {
/// for example references to `Box<str>` or `Arc<str>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub fn as_str(&self) -> &str {
pub const fn as_str(&self) -> &str {
self
}
}