Skip to content

Commit f7e9665

Browse files
authored
Rollup merge of #161271 - yilin0518:fix_coree_wtf8, r=clarfonthey
doc: document safety requirements for core WTF-8 This PR is a follow-up to #160824, and serves as a complementry of `Wtf8` in `alloc` . This PR currently fixes the wtf8 module in `core`, because I noticed that some unsafe APIs in this file do not provide a `safety section`. Therefore, before discharging the call sites, we need to first add the safety section. This PR performs that fix. This PR is related to unstable feature `Wtf8` but this feature don't have relevant tracking issue.
2 parents bf3a87c + c215bed commit f7e9665

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎library/core/src/wtf8.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ impl fmt::Debug for CodePoint {
4949
impl CodePoint {
5050
/// Unsafely creates a new `CodePoint` without checking the value.
5151
///
52-
/// Only use when `value` is known to be less than or equal to 0x10FFFF.
52+
/// # Safety
53+
///
54+
/// `value` must be less than or equal to 0x10FFFF.
5355
#[inline]
5456
pub unsafe fn from_u32_unchecked(value: u32) -> CodePoint {
5557
// SAFETY: Guaranteed by caller.
@@ -210,8 +212,9 @@ impl Wtf8 {
210212

211213
/// Creates a WTF-8 slice from a WTF-8 byte slice.
212214
///
213-
/// Since the byte slice is not checked for valid WTF-8, this functions is
214-
/// marked unsafe.
215+
/// # Safety
216+
///
217+
/// `value` must contain well-formed WTF-8.
215218
#[inline]
216219
pub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8 {
217220
// SAFETY: start with &[u8], end with fancy &[u8]
@@ -220,8 +223,9 @@ impl Wtf8 {
220223

221224
/// Creates a mutable WTF-8 slice from a mutable WTF-8 byte slice.
222225
///
223-
/// Since the byte slice is not checked for valid WTF-8, this functions is
224-
/// marked unsafe.
226+
/// # Safety
227+
///
228+
/// `value` must contain well-formed WTF-8.
225229
#[inline]
226230
pub unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8 {
227231
// SAFETY: start with &mut [u8], end with fancy &mut [u8]

0 commit comments

Comments
 (0)