-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Just like checkpatch.pl
tells developers that they should do their best to avoid BUG*
calls (and if they do, they should be ready to justify them), unwrap()
s (and similar panicking APis like expect()
) in the Rust side are also equally damaging (at least at the moment) since a Rust panic currently calls BUG
s too.
There are cases where unwrap()
is justified (just like unsafe/unchecked operations), but in many cases developers may reach for unwrap()
when there are better alternatives (e.g. reorganizing the code to avoid that case to start with). Even if there is no better alternative and it may be locally obvious that it is an impossible condition, using unwrap()
and similar APIs should be a conscious decision.
Thus introduce a checkpatch.pl
warning for common panicking methods such as unwrap()
and expect()
to make developers think twice about it, as well as to make it easier for maintainers to catch any such use when they check patches they receive.
We may introduce further linting at the source code level for some of those in the future, e.g. #[expect(...)
, possibly with reason = ...
or require // PANIC:
comments.
This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes (including generating the documentation if changed, running the Rust doctests if changed, etc.), to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and to add a Suggested-by:
tag, and a Link:
tag to this issue. Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.