From: Arnaud Lecomte <contact@arnaud-lcm.com>
To: "Andy Whitcroft" <apw@canonical.com>,
"Joe Perches" <joe@perches.com>,
"Dwaipayan Ray" <dwaipayanray1@gmail.com>,
"Lukas Bulwahn" <lukas.bulwahn@gmail.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>,
"Danilo Krummrich" <dakr@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nick Desaulniers" <nick.desaulniers+lkml@gmail.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
llvm@lists.linux.dev, contact@arnaud-lcm.com,
skhan@linuxfoundation.org
Subject: [PATCH 0/2] checkpatch.pl: add warning for // comments on private Rust items
Date: Sat, 19 Apr 2025 22:24:02 +0200 [thread overview]
Message-ID: <20250419-checkpatch-rust-private-item-comment-v1-0-0f8bc109bd5a@arnaud-lcm.com> (raw)
Hi,
Background
----------
The Rust-for-Linux project currently lacks enforcement of documentation for private Rust items,
as highlighted in https://github.com/Rust-for-Linux/linux/issues/1157.
While rustc already lints missing documentation for public items, private items remain unchecked.
This patch series aims to close that gap by ensuring proper documentation practices
for private Rust items in the kernel.
As underlined in this issue:
https://github.com/Rust-for-Linux/linux/issues/1157, the purposes of
this patch serie is to ensure the proper documentation of private rust
items. Public items missing documentation are already linted by rustc.
The actual solution comes in several parts
------------------------------------------
1) Patch 1 : Implements detection logic to emit warnings for improperly
documented private Rust items (e.g., // comments instead of ///).
2) Patch 2 : Adds an auto-fix mechanism via the --fix option to help
developers correct documentation issues.
Results
--------------------
The following implementation has been tested against this input file:
// SPDX-License-Identifier: GPL-2.0
// Simple comment - should not trigger
// Returns a reference to the underlying [`cpufreq::Table`]. - should trigger
fn table(&self) -> &cpufreq::Table {
// SAFETY: The `ptr` is guaranteed by the C code to be valid. - should not trigger
unsafe { cpufreq::Table::from_raw(self.ptr) }
}
// Improper doc comment for a private function. - should trigger
fn test() -> u32 {
42
}
/// Proper doc comment for a private function. - should not trigger
fn proper_doc() -> u32 {
42
}
// TODO: implement more logic - should not trigger
fn todo_marker() -> bool {
true
}
// Just a regular comment not followed by code - should not trigger
pub fn public_function() {
// Public function - should not trigger
}
// Test - should trigger
struct Point2D {
pub x: f32,
pub y: f32
}
// Test - should not trigger
pub struct Point2D {
pub x: f32,
pub y: f32
}
// Test - should not trigger
pub struct Point2D {
pub x: f32,
pub y: f32
}
mod test_module {
// Module inner comment - should not trigger
}
// Comment before macro - should not trigger
macro_rules! my_macro {
// Comment inside macro - should not trigger
() => {};
}
// Comment before unsafe block - should not trigger
unsafe {
// Comment inside unsafe block - should not trigger
let x = 5;
}
// Comment with unsafe word - should trigger
fn with_unsafe_keyword() {
println!("test");
}
// Comment with code example: - should trigger
// let x = 5; - should trigger
fn with_code_example() {
println!("test");
}
// NOTE: important consideration - should not trigger
fn note_marker() -> bool {
true
}
// Comment with code example: - should trigger
/// let x = 5; - should not trigger
fn with_mixed_comments() {
println!("test");
}
which led to this output:
WARNING: Consider using `///` for private item documentation (line 5)
+// Returns a reference to the underlying [`cpufreq::Table`]. - should trigger
WARNING: Consider using `///` for private item documentation (line 12)
+// Improper doc comment for a private function. - should trigger
WARNING: Consider using `///` for private item documentation (line 33)
+// Test - should trigger
WARNING: Consider using `///` for private item documentation (line 74)
+// Comment with unsafe word - should trigger
WARNING: Consider using `///` for private item documentation (line 79)
+// Comment with code example: - should trigger
WARNING: Consider using `///` for private item documentation (line 80)
+// let x = 5; - should trigger
WARNING: Consider using `///` for private item documentation (line 91)
+// Comment with code example: - should trigger
total: 0 errors, 7 warnings, 95 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
test.rs has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
Link: https://github.com/Rust-for-Linux/linux/issues/1157
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Arnaud Lecomte <contact@arnaud-lcm.com>
---
Arnaud Lecomte (2):
checkpatch.pl: warn about // comments on private Rust items
checkpatch.pl: add `--fix` support for `//` comments on private Rust items
scripts/checkpatch.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
---
base-commit: 250b341caf5e0e099dcf789be652178ca57a68cd
change-id: 20250419-checkpatch-rust-private-item-comment-bb3a5281e5da
Best regards,
--
Arnaud Lecomte <contact@arnaud-lcm.com>
next reply other threads:[~2025-04-19 20:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-19 20:24 Arnaud Lecomte [this message]
2025-04-19 21:24 ` [PATCH 1/2] checkpatch.pl: warn about " Arnaud Lecomte
2025-04-19 22:25 ` [PATCH 2/2] checkpatch.pl: add `--fix` support for `//` " Arnaud Lecomte
2025-04-20 8:15 ` [PATCH 0/2] checkpatch.pl: add warning for // " Benno Lossin
-- strict thread matches above, loose matches on Subject: below --
2025-04-19 19:20 Arnaud Lecomte
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=20250419-checkpatch-rust-private-item-comment-v1-0-0f8bc109bd5a@arnaud-lcm.com \
--to=contact@arnaud-lcm.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apw@canonical.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=dwaipayanray1@gmail.com \
--cc=gary@garyguo.net \
--cc=joe@perches.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=lukas.bulwahn@gmail.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®