[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DG3VYAW3TXEO.1YG8N99YWCDR6@garyguo.net>
Date: Sun, 01 Feb 2026 19:51:47 +0000
From: "Gary Guo" <gary@...yguo.net>
To: "Jason Hall" <jason.kei.hall@...il.com>, <apw@...onical.com>,
<joe@...ches.com>, <ojeda@...nel.org>
Cc: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] scripts: checkpatch: warn on Rust panicking methods
On Sun Feb 1, 2026 at 3:57 PM GMT, Jason Hall wrote:
> Added regex check in checkpatch.pl for common Rust panicking methods
> like unwrap() and expect().
>
> Allowed an exception if the line contains a '// PANIC:' comment.
>
> Suggested-by: Miguel Ojeda <ojeda@...nel.org>
> Link: https://github.com/Rust-for-linux/linux/issues/1191
> Signed-off-by: Jason Hall <jason.kei.hall@...il.com>
> ---
> scripts/checkpatch.pl | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index c0250244cf7a..fa9f55031129 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3834,6 +3834,17 @@ sub process {
> # check we are in a valid source file if not then ignore this hunk
> next if ($realfile !~ /\.(h|c|rs|s|S|sh|dtsi|dts)$/);
>
> +# check for Rust unwrap/expect
> + if ($realfile =~ /\.rs$/ && $line =~ /^\+/) {
> + if ($line =~ /\b(unwrap|expect)\s*\(/ &&
> + $rawline !~ /\/\/\s*PANIC/ &&
> + $line !~ /^\+\s*\/\// &&
> + $line !~ /^\+\s*assert/) {
> + WARN("RUST_UNWRAP",
> + "Avoid unwrap() or expect() in Rust code; use proper error handling (Result) or justify with a '// PANIC: ...' comment.\n" . $herecurr);
I don't think `expect()` should need be warned here. There's already
justification being given.
Best,
Gary
> + }
> + }
> +
> # check for using SPDX-License-Identifier on the wrong line number
> if ($realline != $checklicenseline &&
> $rawline =~ /\bSPDX-License-Identifier:/ &&
Powered by blists - more mailing lists