Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7df40e7

Browse files
committedAug 6, 2024
clarify a safety comment
1 parent d90e0f3 commit 7df40e7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎library/core/src/char/methods.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1776,10 +1776,10 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
17761776
dst.len(),
17771777
);
17781778
}
1779-
// SAFETY: it's safe to pretend that the bytes in the slice may be uninitialized
1780-
let dst = unsafe { &mut *(dst as *mut [u8] as *mut [MaybeUninit<u8>]) };
1781-
// SAFETY: `dst` has been checked to be long enough to hold the encoded codepoint
1782-
unsafe { encode_utf8_raw_unchecked(code, dst) }
1779+
1780+
// SAFETY: `encode_utf8_raw_unchecked` only writes initialized bytes to the slice,
1781+
// `dst` has been checked to be long enough to hold the encoded codepoint
1782+
unsafe { encode_utf8_raw_unchecked(code, &mut *(dst as *mut [u8] as *mut [MaybeUninit<u8>])) }
17831783
}
17841784

17851785
/// Encodes a raw u32 value as UTF-8 into the provided possibly uninitialized byte buffer,

0 commit comments

Comments
 (0)
Please sign in to comment.