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

Closed
@fmease

Description

@fmease

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingT-ASTType: Requires working with the AST

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions