Skip to content

Commit

Permalink
Rollup merge of rust-lang#95753 - ChayimFriedman2:patch-1, r=dtolnay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan-DPC authored Apr 7, 2022
2 parents 870ab12 + b399e7e commit 6639604
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down

0 comments on commit 6639604

Please sign in to comment.