[PATCH v4 1/6] rust: switch to `#[expect(...)]` in core modules

Onur Özkan posted 6 patches 3 months, 1 week ago
[PATCH v4 1/6] rust: switch to `#[expect(...)]` in core modules
Posted by Onur Özkan 3 months, 1 week ago
This makes it clear that the warning is expected not just
ignored, so we don't end up having various unnecessary
linting rules in the codebase.

Some parts of the codebase already use this approach, this
patch just applies it more broadly.

No functional changes.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
 rust/kernel/alloc/allocator_test.rs | 2 +-
 rust/kernel/error.rs                | 2 +-
 rust/kernel/types.rs                | 2 +-
 rust/macros/helpers.rs              | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs
index d19c06ef0498..844197d7194e 100644
--- a/rust/kernel/alloc/allocator_test.rs
+++ b/rust/kernel/alloc/allocator_test.rs
@@ -7,7 +7,7 @@
 //! `Cmalloc` allocator within the `allocator_test` module and type alias all kernel allocators to
 //! `Cmalloc`. The `Cmalloc` allocator uses libc's `realloc()` function as allocator backend.

-#![allow(missing_docs)]
+#![expect(missing_docs)]

 use super::{flags::*, AllocError, Allocator, Flags};
 use core::alloc::Layout;
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 3dee3139fcd4..a59613918d4c 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -263,7 +263,7 @@ fn from(e: core::convert::Infallible) -> Error {
 /// [`samples/rust/rust_minimal.rs`]):
 ///
 /// ```
-/// # #[allow(clippy::single_match)]
+/// # #[expect(clippy::single_match)]
 /// fn example() -> Result {
 ///     let mut numbers = KVec::new();
 ///
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 22985b6f6982..a5d5a4737a41 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -600,5 +600,5 @@ pub enum Either<L, R> {
 /// constructed.
 ///
 /// [`NotThreadSafe`]: type@NotThreadSafe
-#[allow(non_upper_case_globals)]
+#[expect(non_upper_case_globals)]
 pub const NotThreadSafe: NotThreadSafe = PhantomData;
diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
index e2602be402c1..6fd1462ff01a 100644
--- a/rust/macros/helpers.rs
+++ b/rust/macros/helpers.rs
@@ -98,7 +98,7 @@ pub(crate) fn file() -> String {
     }

     #[cfg(CONFIG_RUSTC_HAS_SPAN_FILE)]
-    #[allow(clippy::incompatible_msrv)]
+    #[expect(clippy::incompatible_msrv)]
     {
         proc_macro::Span::call_site().file()
     }
--
2.50.0

Re: [PATCH v4 1/6] rust: switch to `#[expect(...)]` in core modules
Posted by Trevor Gross 3 months ago
On Tue Jul 1, 2025 at 12:35 AM CDT, Onur Özkan wrote:
> This makes it clear that the warning is expected not just
> ignored, so we don't end up having various unnecessary
> linting rules in the codebase.
>
> Some parts of the codebase already use this approach, this
> patch just applies it more broadly.
>
> No functional changes.
>
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
> ---

> diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs
> index d19c06ef0498..844197d7194e 100644
> --- a/rust/kernel/alloc/allocator_test.rs
> +++ b/rust/kernel/alloc/allocator_test.rs
> @@ -7,7 +7,7 @@
>  //! `Cmalloc` allocator within the `allocator_test` module and type alias all kernel allocators to
>  //! `Cmalloc`. The `Cmalloc` allocator uses libc's `realloc()` function as allocator backend.
>
> -#![allow(missing_docs)]
> +#![expect(missing_docs)]
>
>  use super::{flags::*, AllocError, Allocator, Flags};
>  use core::alloc::Layout;

If you spin this again, would you mind adding a comment/`reason` about
why there isn't documentation here?

This is preexisting but something to shift the possible meaning from
"this module shouldn't have documentation" to "it's okay that we don't
document unstable test interfaces" would be helpful.

Thanks,
Trevor