diff options
| author | Ralf Jung <post@ralfj.de> | 2024-09-07 21:00:10 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-09-07 21:00:10 +0200 |
| commit | a8a7fd418e217f6b0e66eaa81c3139efdb9174cc (patch) | |
| tree | 860e3deeb9803a798420d942c8c58d636c4121b8 | |
| parent | 009e73825af0e59ad4fc603562e038b3dbd6593a (diff) | |
| download | rust-a8a7fd418e217f6b0e66eaa81c3139efdb9174cc.tar.gz rust-a8a7fd418e217f6b0e66eaa81c3139efdb9174cc.zip | |
str: make as_mut_ptr and as_bytes_mut unstably const
| -rw-r--r-- | library/core/src/str/mod.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index cf9f1bfc0eb..e947686487e 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -338,9 +338,10 @@ impl str { /// assert_eq!("🍔∈🌏", s); /// ``` #[stable(feature = "str_mut_extras", since = "1.20.0")] + #[rustc_const_unstable(feature = "const_str_as_mut", issue = "130086")] #[must_use] #[inline(always)] - pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] { + pub const unsafe fn as_bytes_mut(&mut self) -> &mut [u8] { // SAFETY: the cast from `&str` to `&[u8]` is safe since `str` // has the same layout as `&[u8]` (only std can make this guarantee). // The pointer dereference is safe since it comes from a mutable reference which @@ -383,10 +384,11 @@ impl str { /// It is your responsibility to make sure that the string slice only gets /// modified in a way that it remains valid UTF-8. #[stable(feature = "str_as_mut_ptr", since = "1.36.0")] + #[rustc_const_unstable(feature = "const_str_as_mut", issue = "130086")] #[rustc_never_returns_null_ptr] #[must_use] #[inline(always)] - pub fn as_mut_ptr(&mut self) -> *mut u8 { + pub const fn as_mut_ptr(&mut self) -> *mut u8 { self as *mut str as *mut u8 } |
