From: Alice Ryhl <aliceryhl@google.com>
To: Navaneeth K <knavaneeth786@gmail.com>
Cc: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] rust: kernel: document safety for as_str_unchecked
Date: Mon, 24 Nov 2025 09:34:19 +0000 [thread overview]
Message-ID: <aSQmmxRzFR0Bqj1v@google.com> (raw)
In-Reply-To: <20251122190908.259929-3-knavaneeth786@gmail.com>
On Sat, Nov 22, 2025 at 07:09:08PM +0000, Navaneeth K wrote:
> 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@gmail.com>
> ---
> 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()) }
As far as I know another patch is deleting this method, so I don't think
there is anything to fix anymore.
Alice
prev parent reply other threads:[~2025-11-24 9:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 19:09 [PATCH 0/2] rust: kernel: add missing safety documentation Navaneeth K
2025-11-22 19:09 ` [PATCH 1/2] rust: kernel: document safety for rust_fmt_argument Navaneeth K
2025-11-22 19:09 ` [PATCH 2/2] rust: kernel: document safety for as_str_unchecked Navaneeth K
2025-11-24 9:34 ` Alice Ryhl [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSQmmxRzFR0Bqj1v@google.com \
--to=aliceryhl@google.com \
--cc=alex.gaynor@gmail.com \
--cc=knavaneeth786@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).