From b399e7ea7c99a24f43e9562b0fb5223833a8bb50 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Thu, 7 Apr 2022 07:52:07 +0300 Subject: [PATCH] Correct safety reasoning in `str::make_ascii_{lower,upper}case()` --- library/core/src/str/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 6bfa6a5e015..82208c4deaa 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2407,7 +2407,7 @@ pub fn eq_ignore_ascii_case(&self, other: &str) -> bool { #[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 @@ pub fn make_ascii_uppercase(&mut self) { #[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() }