Skip to content

Fix four_forward_slashes false positive on inner doc comments#17448

Open
zakrad wants to merge 1 commit into
rust-lang:masterfrom
zakrad:fix-16168-inner-doc-comments
Open

Fix four_forward_slashes false positive on inner doc comments#17448
zakrad wants to merge 1 commit into
rust-lang:masterfrom
zakrad:fix-16168-inner-doc-comments

Conversation

@zakrad

@zakrad zakrad commented Jul 23, 2026

Copy link
Copy Markdown

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:

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.

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 23, 2026
@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot

This comment has been minimized.

The lint computes the item's end line from a span folded over the item's
doc-comment attributes, then scans the lines above for `////`. The fold
previously included inner doc comments (`//!`); an inner doc inside the body
lowers onto the item with `AttrStyle::Inner`, so folding its span pushed the
end line down into the body and the upward scan flagged a regular `////`
comment there — whose suggested fix (`///`) then fails to compile.

Fold in outer doc comments only, mirroring the pattern in
`doc/suspicious_doc_comments.rs`.
@zakrad
zakrad force-pushed the fix-16168-inner-doc-comments branch from baa9f90 to 4d9d3f8 Compare July 23, 2026 22:06

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

community review: looks good to me

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

four-forward-slashes thinks module-level docs are items that can be documented

3 participants