[06/13] rust: str: move SAFETY comment in front of unsafe block

Message ID 20240116220615.168083-1-kernel@valentinobst.de
State New
Headers
Series rust: kernel: documentation improvements |

Commit Message

Valentin Obst Jan. 16, 2024, 10:06 p.m. UTC
  SAFETY comments should immediately precede the unsafe block they
justify. Move assignment to `bar` past comment as it is safe.

Signed-off-by: Valentin Obst <kernel@valentinobst.de>
---
 rust/kernel/str.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Trevor Gross Jan. 18, 2024, 12:48 a.m. UTC | #1
On Tue, Jan 16, 2024 at 5:36 PM Valentin Obst <kernel@valentinobst.de> wrote:
>
> SAFETY comments should immediately precede the unsafe block they
> justify. Move assignment to `bar` past comment as it is safe.
>
> Signed-off-by: Valentin Obst <kernel@valentinobst.de>
> ---
>  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 843ffeec9b3e..fec5c4314758 100644
> --- a/rust/kernel/str.rs
> +++ b/rust/kernel/str.rs
> @@ -191,9 +191,9 @@ pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> {
>      /// ```
>      /// # use kernel::c_str;
>      /// # use kernel::str::CStr;
> +    /// let bar = c_str!("ツ");
>      /// // SAFETY: String literals are guaranteed to be valid UTF-8
>      /// // by the Rust compiler.
> -    /// let bar = c_str!("ツ");
>      /// assert_eq!(unsafe { bar.as_str_unchecked() }, "ツ");
>      /// ```
>      #[inline]
> --
> 2.43.0
>
>

Reviewed-by: Trevor Gross <tmgross@umich.edu>
  

Patch

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 843ffeec9b3e..fec5c4314758 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -191,9 +191,9 @@  pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> {
     /// ```
     /// # use kernel::c_str;
     /// # use kernel::str::CStr;
+    /// let bar = c_str!("ツ");
     /// // SAFETY: String literals are guaranteed to be valid UTF-8
     /// // by the Rust compiler.
-    /// let bar = c_str!("ツ");
     /// assert_eq!(unsafe { bar.as_str_unchecked() }, "ツ");
     /// ```
     #[inline]