Merge pull request #20977 from chirizxc/patch-1

Move safe computation out of unsafe block
This commit is contained in:
Laurențiu Nicola 2025-11-06 08:47:03 +00:00 committed by GitHub
commit 3668c75171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,8 +62,8 @@ impl LineEndings {
// Account for removed `\r`.
// After `set_len`, `buf` is guaranteed to contain utf-8 again.
let new_len = buf.len() - gap_len;
let src = unsafe {
let new_len = buf.len() - gap_len;
buf.set_len(new_len);
String::from_utf8_unchecked(buf)
};