Skip to content

Commit 6fd742b

Browse files
hoshinolinajannau
authored andcommitted
kernel: str: Add/fix SAFETY comments
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 58420ac commit 6fd742b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

rust/kernel/str.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl fmt::Display for BStr {
4848
/// let s = CString::try_from_fmt(fmt!("{}", ascii)).unwrap();
4949
/// assert_eq!(s.as_bytes(), "Hello, BStr!".as_bytes());
5050
///
51-
/// let non_ascii = b_str!("🦀");
51+
/// let non_ascii = b_str!("");
5252
/// let s = CString::try_from_fmt(fmt!("{}", non_ascii)).unwrap();
5353
/// assert_eq!(s.as_bytes(), "\\xf0\\x9f\\xa6\\x80".as_bytes());
5454
/// ```
@@ -79,7 +79,7 @@ impl fmt::Debug for BStr {
7979
/// let s = CString::try_from_fmt(fmt!("{:?}", ascii)).unwrap();
8080
/// assert_eq!(s.as_bytes(), "\"Hello, \\\"BStr\\\"!\"".as_bytes());
8181
///
82-
/// let non_ascii = b_str!("😺");
82+
/// let non_ascii = b_str!("");
8383
/// let s = CString::try_from_fmt(fmt!("{:?}", non_ascii)).unwrap();
8484
/// assert_eq!(s.as_bytes(), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes());
8585
/// ```
@@ -306,7 +306,7 @@ impl CStr {
306306
/// ```
307307
#[inline]
308308
pub unsafe fn as_str_unchecked(&self) -> &str {
309-
// SAFETY: TODO.
309+
// SAFETY: Depends on the above safety contract
310310
unsafe { core::str::from_utf8_unchecked(self.as_bytes()) }
311311
}
312312

@@ -389,7 +389,7 @@ impl fmt::Display for CStr {
389389
/// # use kernel::fmt;
390390
/// # use kernel::str::CStr;
391391
/// # use kernel::str::CString;
392-
/// let penguin = c_str!("🐧");
392+
/// let penguin = c_str!("");
393393
/// let s = CString::try_from_fmt(fmt!("{}", penguin)).unwrap();
394394
/// assert_eq!(s.as_bytes_with_nul(), "\\xf0\\x9f\\x90\\xa7\0".as_bytes());
395395
///
@@ -418,7 +418,7 @@ impl fmt::Debug for CStr {
418418
/// # use kernel::fmt;
419419
/// # use kernel::str::CStr;
420420
/// # use kernel::str::CString;
421-
/// let penguin = c_str!("🐧");
421+
/// let penguin = c_str!("");
422422
/// let s = CString::try_from_fmt(fmt!("{:?}", penguin)).unwrap();
423423
/// assert_eq!(s.as_bytes_with_nul(), "\"\\xf0\\x9f\\x90\\xa7\"\0".as_bytes());
424424
///
@@ -572,7 +572,7 @@ mod tests {
572572
let good_bytes = b"\xf0\x9f\xa6\x80\0";
573573
let checked_cstr = CStr::from_bytes_with_nul(good_bytes).unwrap();
574574
let checked_str = checked_cstr.to_str().unwrap();
575-
assert_eq!(checked_str, "🦀");
575+
assert_eq!(checked_str, "");
576576
}
577577

578578
#[test]
@@ -588,7 +588,7 @@ mod tests {
588588
let good_bytes = b"\xf0\x9f\x90\xA7\0";
589589
let checked_cstr = CStr::from_bytes_with_nul(good_bytes).unwrap();
590590
let unchecked_str = unsafe { checked_cstr.as_str_unchecked() };
591-
assert_eq!(unchecked_str, "🐧");
591+
assert_eq!(unchecked_str, "");
592592
}
593593

594594
#[test]

0 commit comments

Comments
 (0)