Skip to contentSkip to conversation

rust: resolve safety comment TODO in `as_str_unchecked`

PATCH In review Onur Özkan 2 participants 2 messages Sep 11, 2025 – Jan 18 Rust

lore
Share & tools
lore

Onur Özkan

author reviewer
#0 lore raw

PATCH 1/1 rust: resolve safety comment TODO in `as_str_unchecked`

Resolved the TODO comment with a proper safety explanation.

---
 rust/kernel/str.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/str.rs +2 -1
index 6c892550c0ba..11c30c765828 100644
@@ -380,7 +380,8 @@ pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> {
     /// ```
     #[inline]
     pub unsafe fn as_str_unchecked(&self) -> &str {
-        // SAFETY: TODO.
+        // SAFETY: The safety precondition guarantees that the contents
+        // of this `CStr` are valid UTF-8.
         unsafe { core::str::from_utf8_unchecked(self.as_bytes()) }
     }
 

--
2.50.0

#1 lore raw
Quoted 4 lines · Onur Özkan

Resolved the TODO comment with a proper safety explanation.

I saw this patch without replies -- for future reference, commit 3b83f5d5e78a ("rust: replace CStr with core::ffi::CStr") made this one not needed.

Thanks!

Cheers,
Miguel