Skip to content

Commit 5e6342d

Browse files
authored
Merge pull request #2473 from phansch/handle_multiline_attributes
Lint multiline attributes properly
2 parents a7407f9 + d3d3d7d commit 5e6342d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

clippy_lints/src/attrs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,18 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
271271
return;
272272
}
273273

274-
let attr_to_item_span = Span::new(attr.span.lo(), span.lo(), span.ctxt());
274+
let begin_of_attr_to_item = Span::new(attr.span.lo(), span.lo(), span.ctxt());
275+
let end_of_attr_to_item = Span::new(attr.span.hi(), span.lo(), span.ctxt());
275276

276-
if let Some(snippet) = snippet_opt(cx, attr_to_item_span) {
277+
if let Some(snippet) = snippet_opt(cx, end_of_attr_to_item) {
277278
let lines = snippet.split('\n').collect::<Vec<_>>();
278-
if lines.iter().filter(|l| l.trim().is_empty()).count() > 1 {
279+
if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
279280
span_lint(
280281
cx,
281282
EMPTY_LINE_AFTER_OUTER_ATTR,
282-
attr_to_item_span,
283+
begin_of_attr_to_item,
283284
"Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?"
284-
);
285-
285+
);
286286
}
287287
}
288288
}

tests/ui/empty_line_after_outer_attribute.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,13 @@ mod foo {
5858
#[allow(missing_docs)]
5959
fn three_attributes() { assert!(true) }
6060

61+
// This should not produce a warning
62+
#[doc = "
63+
Returns the escaped value of the textual representation of
64+
65+
"]
66+
pub fn function() -> bool {
67+
true
68+
}
69+
6170
fn main() { }

0 commit comments

Comments
 (0)