Skip to content

Commit 6639604

Browse files
authored
Rollup merge of rust-lang#95753 - ChayimFriedman2:patch-1, r=dtolnay
Correct safety reasoning in `str::make_ascii_{lower,upper}case()` I don't understand why the previous comment was used (it was inserted in rust-lang#66564), but it doesn't explain why these functions are safe, only why `str::as_bytes{_mut}()` are safe. If someone thinks they make perfect sense, I'm fine with closing this PR.
2 parents 870ab12 + b399e7e commit 6639604

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/core/src/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ impl str {
24072407
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
24082408
#[inline]
24092409
pub fn make_ascii_uppercase(&mut self) {
2410-
// SAFETY: safe because we transmute two types with the same layout.
2410+
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
24112411
let me = unsafe { self.as_bytes_mut() };
24122412
me.make_ascii_uppercase()
24132413
}
@@ -2434,7 +2434,7 @@ impl str {
24342434
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
24352435
#[inline]
24362436
pub fn make_ascii_lowercase(&mut self) {
2437-
// SAFETY: safe because we transmute two types with the same layout.
2437+
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
24382438
let me = unsafe { self.as_bytes_mut() };
24392439
me.make_ascii_lowercase()
24402440
}

0 commit comments

Comments
 (0)