Skip to content

Lint empty_line_after_doc_comments emits a slightly butchered diagnostic note if the following item is of a kind that doesn't have a name #14515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fmease opened this issue Apr 1, 2025 · 1 comment · Fixed by #14584
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing T-AST Type: Requires working with the AST

Comments

@fmease
Copy link
Member

fmease commented Apr 1, 2025

Found this while reviewing PR rust-lang/rust#138740: See rust-lang/rust#138740 (comment).

The diagnostic emitted by lint empty_line_after_doc_comments highlights the following item if present and notes if the doc comment should not document `NAME` comment it out where NAME is the name of the item. However, there are item kinds that don't (quite) have a name, namely Use, ForeignMod, GlobalAsm, Impl, MacCall, DelegationMac if we're talking about the AST (and not the HIR).

In the rustc that Clippy currently uses such AST items bear an empty name (as a dummy placeholder) and Clippy blindly leaks it to users. Consider:

#![deny(clippy::empty_line_after_doc_comments)]

/// X
// fn f() {}

impl Ty {}
struct Ty;
error: empty line after doc comment
 --> src/lib.rs:3:1
  |
3 | / /// X
4 | | // fn f() {}
5 | |
  | |_^
6 |   impl Ty {}
  |   ------- the comment documents this implementation
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![deny(clippy::empty_line_after_doc_comments)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: if the empty line is unintentional remove it
help: if the doc comment should not document `` comment it out
  |
3 | // /// X
  | ++

Notice the last subdiagnostic.

I'll fix this after the Clippy sync once it includes PR rust-lang/rust#138740 (which would make the fix less hacky). Blocking it on the next sync.

@rustbot claim
@rustbot label C-bug S-blocked T-AST

@rustbot rustbot added C-bug Category: Clippy is not doing the correct thing S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work T-AST Type: Requires working with the AST labels Apr 1, 2025
@fmease
Copy link
Member Author

fmease commented Apr 10, 2025

The sync has happened @rustbot label -S-blocked

@rustbot rustbot removed the S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work label Apr 10, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 10, 2025
… the following item is nameless (#14584)

Fixes #14515.

changelog: [`empty_line_after_doc_comments`]: Fix a help message for
cases where the following item is nameless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing T-AST Type: Requires working with the AST
Projects
None yet
2 participants