Re: [PATCH v5] scripts: checkpatch: move Rust-specific lints to separate file
From: Dirk Behme
Date: Fri Feb 06 2026 - 03:32:08 EST
On 05.02.2026 21:55, Miguel Ojeda wrote:
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
Gary had some concerns about `expect()` in
https://lore.kernel.org/rust-for-linux/DG3VYAW3TXEO.1YG8N99YWCDR6@xxxxxxxxxxx/
kernel code modulo some exceptions (e.g. within asserts in doctests
... and `tests`)
? See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/rust/kernel/alloc/kvec.rs?h=v6.19-rc8#n1355
).
If the use is intended, then please justify it with a `// PANIC:`
comment. Please see ...
I'm totally fine with this. In consequence do we agree that this will result in some follow up patches annotating the existing "allowed" exceptional / intended cases (e.g. in doctests and tests) with `// PANIC:` comments?
Best regards
Dirk
But I will let others comment...
(Also, please Cc all the maintainers/reviews of Rust and checkpatch --
doing so here).
Thanks!
Cheers,
Miguel