Skip to content

Commit 79d04e7

Browse files
committed
docs: rust: explain that /// vs. // applies to private items too
Sometimes kernel developers use `//` for documenting private items, since those do not get rendered at the moment. That is reasonable, but the intention behind `///` (and `//!`) vs. `//` is to convey the distinction between documentation and other kinds of comments, such as implementation details or TODOs. It also increases consistency with the public items and thus e.g. allows to change visibility of an item with less changes involved. It is not just useful for human readers, but also tooling. For instance, we may want to eventually generate documentation for private items (perhaps as a toggle in the HTML UI). On top of that, `rustdoc` lints as usual for those, too, so we may want to do it even if we do not use the result. Thus document this explicitly. Link: https://lore.kernel.org/rust-for-linux/CANiq72n_C7exSOMe5yf-7jKKnhSCv+a9QcD=OE2B_Q2UFBL3Xg@mail.gmail.com/ Link: #1157 Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Christian Schrefl <[email protected]> Reviewed-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Fixed typo. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 878620c commit 79d04e7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Documentation/rust/coding-guidelines.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ written after the documentation, e.g.:
8585
// ...
8686
}
8787
88+
This applies to both public and private items. This increases consistency with
89+
public items, allows changes to visibility with less changes involved and will
90+
allow us to potentially generate the documentation for private items as well.
91+
In other words, if documentation is written for a private item, then ``///``
92+
should still be used. For instance:
93+
94+
.. code-block:: rust
95+
96+
/// My private function.
97+
// TODO: ...
98+
fn f() {}
99+
88100
One special kind of comments are the ``// SAFETY:`` comments. These must appear
89101
before every ``unsafe`` block, and they explain why the code inside the block is
90102
correct/sound, i.e. why it cannot trigger undefined behavior in any case, e.g.:

0 commit comments

Comments
 (0)