workflows.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Manas via B4 Relay <devnull+manas18244.iiitd.ac.in@kernel.org>
To: "Dwaipayan Ray" <dwaipayanray1@gmail.com>,
	"Lukas Bulwahn" <lukas.bulwahn@gmail.com>,
	"Joe Perches" <joe@perches.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Andy Whitcroft" <apw@canonical.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	 Anup Sharma <anupnewsmail@gmail.com>,
	workflows@vger.kernel.org,  linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,  rust-for-linux@vger.kernel.org,
	Manas <manas18244@iiitd.ac.in>
Subject: [PATCH] scripts: checkpatch: add check for simplifying Result<()> in Rust
Date: Thu, 28 Nov 2024 23:31:01 +0530	[thread overview]
Message-ID: <20241128-add-checkpatch-result-simplify-v1-1-973603191d71@iiitd.ac.in> (raw)

From: Manas <manas18244@iiitd.ac.in>

The type Result<()> can be rewritten simply as Result, as default type
parameters are unit `()` and `Error` types already. Thus keep usage of
`Result` consistent throughout codebase.

Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1128
Not-yet-signed-off-by: Manas <manas18244@iiitd.ac.in>
---
Note: The blockage due to my Signed-off-by tag is being resolved in
private. For now I am adding Not-yet-signed-off-by tag.
---
 Documentation/dev-tools/checkpatch.rst | 10 ++++++++++
 scripts/checkpatch.pl                  |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index abb3ff6820766ee0c29112b256bcc44ce41fffba..7bf1fc7d4d7b490b32b8863365afe12a6732d6c1 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -1018,6 +1018,16 @@ Functions and Variables
 
       return bar;
 
+  **SIMPLIFIED_RESULT**
+    simplifies Result<()> in Rust codebase as Result because default type
+    parameters are unit and Error types::
+
+      fn foo(x: Result<()>) -> Result<()> {}
+
+    can be rewritten as::
+
+      fn foo(x: Result) -> Result {}
+
 
 Permissions
 -----------
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9eed3683ad76caffbbb2418e5dbea7551d374406..ddc943fd4a62d58cee92f8723e7634af4ca69e32 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3574,6 +3574,15 @@ sub process {
 			}
 		}
 
+# Check for Result<()> usage in Rust code
+    if ($realfile =~ /\.rs$/ &&
+        $sline =~ /^\+.*Result<\(\)>/) {
+      $check = 1;
+      if (CHK("SIMPLIFIED_RESULT", "Result<()> can be rewritten simply as Result\n" . $herecurr) && $fix) {
+        $fixed[$fixlinenr] =~ s/Result<\(\)>/Result/g;
+      }
+    }
+
 # ignore non-hunk lines and lines being removed
 		next if (!$hunk_line || $line =~ /^-/);
 

---
base-commit: 1dc707e647bc919834eff9636c8d00b78c782545
change-id: 20241125-add-checkpatch-result-simplify-8def44860489

Best regards,
-- 
Manas <manas18244@iiitd.ac.in>



                 reply	other threads:[~2024-11-28 18:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241128-add-checkpatch-result-simplify-v1-1-973603191d71@iiitd.ac.in \
    --to=devnull+manas18244.iiitd.ac.in@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=anupnewsmail@gmail.com \
    --cc=apw@canonical.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dwaipayanray1@gmail.com \
    --cc=gary@garyguo.net \
    --cc=joe@perches.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=manas18244@iiitd.ac.in \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tmgross@umich.edu \
    --cc=workflows@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).