Re: [PATCH v5] scripts: checkpatch: move Rust-specific lints to separate file
From: Miguel Ojeda
Date: Thu Feb 05 2026 - 15:55:51 EST
On Thu, Feb 5, 2026 at 2:42 AM Jason Hall <jason.kei.hall@xxxxxxxxx> wrote:
>
> Move Rust linting logic into scripts/rust_checkpatch.pl to prevent
> further growth of the main checkpatch.pl script.
>
> Warn against the use of .unwrap() and .expect() unless accompanied by
> a '// PANIC:' comment. This enforces safety standards in the Rust-
> for-Linux project until upstream Clippy lints are integrated.
>
> Suggested-by: Joe Perches <joe@xxxxxxxxxxx>
> Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
> Link: https://github.com/Rust-for-linux/linux/issues/1191
> Signed-off-by: Jason Hall <jason.kei.hall@xxxxxxxxx>
Ideally, this would be two patches -- one performing the move and the
other adding the new lint.
Either way, the file should be added to `MAINTAINERS` -- not sure if
Joe would want to maintain it or perhaps have a new sub-entry or
perhaps a co-maintainer etc.
> + "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
By "proper error handling", I guess you mean bubbling the error up
with `?` or similar, right?
There are also other options, like using `unsafe` sometimes etc.
I think perhaps the best is to keep the message a bit less strict
(since there are cases where it is OK) and put the details in a link
to, say, https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
(Cc'ing Dirk who was involved in that).
I am thinking of something like:
`unwrap()` and `expect()` should generally be avoided in Rust
kernel code modulo some exceptions (e.g. within asserts in doctests).
If the use is intended, then please justify it with a `// PANIC:`
comment. Please see ...
But I will let others comment...
(Also, please Cc all the maintainers/reviews of Rust and checkpatch --
doing so here).
Thanks!
Cheers,
Miguel