[PATCH] rust: resolve safety comment TODO in `as_str_unchecked`

Onur Özkan posted 1 patch 3 weeks ago
rust/kernel/str.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] rust: resolve safety comment TODO in `as_str_unchecked`
Posted by Onur Özkan 3 weeks ago
Resolved the TODO comment with a proper safety explanation.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
 rust/kernel/str.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 6c892550c0ba..11c30c765828 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -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