Skip to content

Commit

Permalink
Fix false positive in empty_line_after_outer_attr
Browse files Browse the repository at this point in the history
Doc comments are syntactic sugar for #[doc] attributes, so this lint was
catching them, too.

This commit makes it so that doc comments are ignored in this lint.

I think, for normal attributes it makes sense to warn about following empty
lines, for doc comments, less. This way the user has some freedom over
the formatting.
  • Loading branch information
phansch committed Feb 1, 2018
1 parent ee8d328 commit a64724f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
}

for attr in attrs {
if attr.is_sugared_doc {
return;
}
if attr.style == AttrStyle::Outer {
if !is_present_in_source(cx, attr.span) {
return;
Expand All @@ -276,7 +279,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
cx,
EMPTY_LINE_AFTER_OUTER_ATTR,
attr_to_item_span,
&format!("Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?")
"Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?"
);

}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/empty_line_after_outer_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ struct Foo {
mod foo {
}

/// This doc comment should not produce a warning

/** This is also a doc comment and should not produce a warning
*/

// This should not produce a warning
#[allow(non_camel_case_types)]
#[allow(missing_docs)]
Expand Down

0 comments on commit a64724f

Please sign in to comment.