Correct safety reasoning in str::make_ascii_{lower,upper}case()

This commit is contained in:
Chayim Refael Friedman 2022-04-07 07:52:07 +03:00 committed by GitHub
parent 2310da432c
commit b399e7ea7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2407,7 +2407,7 @@ impl str {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn make_ascii_uppercase(&mut self) {
// SAFETY: safe because we transmute two types with the same layout.
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_uppercase()
}
@ -2434,7 +2434,7 @@ impl str {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn make_ascii_lowercase(&mut self) {
// SAFETY: safe because we transmute two types with the same layout.
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_lowercase()
}