Skip to content

Commit 997f804

Browse files
committed
fix: warn on empty line outer AttrKind::DocComment
1 parent 8f0ba1f commit 997f804

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

clippy_lints/src/attrs.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl EarlyLintPass for EarlyAttributes {
622622
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
623623
let mut iter = item.attrs.iter().peekable();
624624
while let Some(attr) = iter.next() {
625-
if matches!(attr.kind, AttrKind::Normal(..))
625+
if (matches!(attr.kind, AttrKind::Normal(..)) || matches!(attr.kind, AttrKind::DocComment(..)))
626626
&& attr.style == AttrStyle::Outer
627627
&& is_present_in_source(cx, attr.span)
628628
{
@@ -639,13 +639,17 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
639639
let lines = without_block_comments(lines);
640640

641641
if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
642-
span_lint(
643-
cx,
644-
EMPTY_LINE_AFTER_OUTER_ATTR,
645-
begin_of_attr_to_item,
646-
"found an empty line after an outer attribute. \
647-
Perhaps you forgot to add a `!` to make it an inner attribute?",
648-
);
642+
let lint_mst = match attr.kind {
643+
AttrKind::Normal(..) => {
644+
"found an empty line after an outer attribute. \
645+
Perhaps you forgot to add a `!` to make it an inner attribute?"
646+
},
647+
AttrKind::DocComment(..) => {
648+
"found an empty line after an outer doc comment. \
649+
Perhaps you need to use `//!` to make a comment on the module or remove the empty line?"
650+
},
651+
};
652+
span_lint(cx, EMPTY_LINE_AFTER_OUTER_ATTR, begin_of_attr_to_item, lint_mst);
649653
}
650654
}
651655
}

0 commit comments

Comments
 (0)