workflows.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: checkpatch: add check for simplifying Result<()> in Rust
@ 2024-11-28 18:01 Manas via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Manas via B4 Relay @ 2024-11-28 18:01 UTC (permalink / raw)
  To: Dwaipayan Ray, Lukas Bulwahn, Joe Perches, Jonathan Corbet,
	Andy Whitcroft, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross
  Cc: Shuah Khan, Anup Sharma, workflows, linux-doc, linux-kernel,
	rust-for-linux, Manas

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>



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-11-28 18:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28 18:01 [PATCH] scripts: checkpatch: add check for simplifying Result<()> in Rust Manas via B4 Relay

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).