[PATCH 2/2] rust: kernel: document safety for as_str_unchecked

From: Navaneeth K

Date: Sat Nov 22 2025 - 14:09:45 EST


Replace the TODO safety comment with a proper explanation.
The safety of from_utf8_unchecked relies on the caller guaranteeing
that the input bytes are valid UTF-8.

Signed-off-by: Navaneeth K <knavaneeth786@xxxxxxxxx>
---
rust/kernel/str.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 5c74e5f77601..2801388c6bd1 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -385,7 +385,7 @@ pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> {
/// ```
#[inline]
pub unsafe fn as_str_unchecked(&self) -> &str {
- // SAFETY: TODO.
+ // SAFETY: The caller guarantees that the contents are valid UTF-8.
unsafe { core::str::from_utf8_unchecked(self.as_bytes()) }
}

--
2.43.0