rust-lang / rust-lang/rust-clippy
Suspicious comment (//) adjacent to doc comment (///)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
If a // comment is found adjacent to a doc comment, warn, as it may have been intended to be part of the doc comment.
Some cases that definitely should be warned about:
- a
//comment above a///doc comment empty line - a
//comment (either single or multi-line) surrounded by doc comment lines
Some edge cases:
- a
//comment before a doc comment - a `// comment after a doc comment
Some cases that should definitely be excluded:
- comments beginning with an all-caps word, like
TODO,FIXME,PERF - comments defined by
/* */, as that is much harder to typo
Lint Name
suspicious-comment-beside-doc-comment
Category
suspicious
Advantage
Ordinary comments do not appear in generated documentation.
Drawbacks
- It becomes harder to comment on the documentation itself. This is a pretty rare pattern; usually I'd use issue trackers for that sort of thing.
- The exact rule should be tuned to make sure that doc comments on a struct / function can exist beside ordinary comments without triggering false positives.
Example
// Consumes the [`OwningPtr`] to obtain ownership of the underlying data of type `T`.
///
/// # Safety
/// Must point to a valid `T`.
Was likely intended to be
/// Consumes the [`OwningPtr`] to obtain ownership of the underlying data of type `T`.
///
/// # Safety
/// Must point to a valid `T`.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are identified in the issue. Start by locating Clippy's existing suspicious-comment lints and their tests, then define the adjacency cases and exclusions described here; done means the new lint warns on the specified // and /// patterns without flagging uppercase marker comments or /* */ comments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100