File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -183,10 +183,10 @@ pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
183
183
/// ```
184
184
#[ inline]
185
185
#[ stable( feature = "str_mut_extras" , since = "1.20.0" ) ]
186
- pub unsafe fn from_utf8_unchecked_mut ( v : & mut [ u8 ] ) -> & mut str {
187
- // SAFETY: the caller must guarantee that the bytes `v`
188
- // are valid UTF-8, thus the cast to `* mut str` is safe.
189
- // Also, the pointer dereference is safe because that pointer
190
- // comes from a reference which is guaranteed to be valid for writes .
191
- unsafe { & mut * ( v as * mut [ u8 ] as * mut str ) }
186
+ # [ rustc_const_stable ( feature = "const_str_from_utf8_unchecked" , since = "1.55.0" ) ]
187
+ # [ rustc_allow_const_fn_unstable ( const_fn_transmute ) ]
188
+ pub const unsafe fn from_utf8_unchecked_mut ( v : & mut [ u8 ] ) -> & mut str {
189
+ // SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
190
+ // Also relies on `&mut str` and `&mut [u8]` having the same layout .
191
+ unsafe { mem :: transmute ( v ) }
192
192
}
You can’t perform that action at this time.
0 commit comments