Commit 7488a0d
authored
Fix
`four_forward_slashes` scans the lines above an item for `////` comments
and suggests turning them into `///`. It derives the item's start line
from a span folded over the item's doc-comment attributes, but that fold
included *inner* doc comments (`//!`).
An inner `//!` inside a body lowers onto the item with
`AttrStyle::Inner`; folding its span pushes the item's end line down
into the body, so the upward scan then flags a regular `////` comment
there. Applying the suggestion rewrites it to `///`, which documents
nothing and fails to compile (E0585).
Repro from the issue:
```rust
pub fn main() {
//// I am not a doc comment!
//! another comment
}
```
Fix: fold in outer doc comments only, mirroring the existing pattern in
`clippy_lints/src/doc/suspicious_doc_comments.rs`. A genuine `////` typo
above an item still lints, and I added a regression test for the
inner-doc case.
Fixes #16168
changelog: [`four_forward_slashes`]: no longer fires on `////` comments
that sit above an inner doc comment (`//!`) in an item's body
---
Disclosure: I used AI assistance to help diagnose the root cause and
draft this change. It's a small, self-contained fix that I've reviewed,
tested locally (`cargo uitest` + `cargo dev fmt`), and can explain.four_forward_slashes false positive on inner doc comments (#17448)3 files changed
Lines changed: 30 additions & 2 deletions
File tree
- clippy_lints/src
- tests/ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | | - | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
52 | 66 | | |
53 | 67 | | |
54 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments