Re: [PATCH] rust: replace `build_assert!` with `const_assert!`

From: Miguel Ojeda

Date: Mon Mar 30 2026 - 06:12:26 EST


On Mon, Mar 30, 2026 at 4:03 AM Mohamad Alsadhan <mo@xxxxxxx> wrote:
>
> Several Rust assertions currently use the `build_assert!` macro
> despite their conditions only depending on type parameters or const
> generics, not runtime values.
>
> Replace these with the more appropriate `const_assert!` macro which
> should trigger earlier in the compilation pipeline. This is possible
> since commit 560a7a9b9 ("rust: add `const_assert!` macro").
>
> No functional change intended.
>
> Signed-off-by: Mohamad Alsadhan <mo@xxxxxxx>

These are the ones identified by your Klint PR, right?

It would be nice to mention that and link to it, so I can do that on apply:

Link: https://github.com/Rust-for-Linux/klint/pull/13

...especially considering the recently added guidelines, i.e. things
like Coccinelle would apply:

https://docs.kernel.org/process/generated-content.html

But it is also good publicity for Klint, it may get others to run it ;)

> rust/kernel/dma.rs | 4 ++--
> rust/kernel/i2c.rs | 2 +-
> rust/kernel/sync/locked_by.rs | 8 ++++----
> rust/kernel/xarray.rs | 4 ++--

Let's see if we get Acked-bys; otherwise, the patch could also be
split and sent individually to subsystems.

Cc'ing the maintainers as well (`scripts/get_maintainer.pl` is used to
get the names and email of who to Cc in most cases -- please use it
when sending future patches).

Thanks!

Cheers,
Miguel