Skip to content

Commit 642b321

Browse files
committed
Add workaround for hidden outer attribute
1 parent eaee569 commit 642b321

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clippy_lints/src/attrs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc::ty::{self, TyCtxt};
77
use semver::Version;
88
use syntax::ast::{Attribute, AttrStyle, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
99
use syntax::codemap::Span;
10+
use syntax_pos::{Pos};
1011
use utils::{in_macro, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_then};
1112

1213
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
@@ -267,7 +268,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
267268

268269
if let Some(snippet) = snippet_opt(cx, attr_to_item_span) {
269270
let lines = snippet.split('\n').collect::<Vec<_>>();
270-
if lines.iter().filter(|l| l.trim().is_empty()).count() > 1 {
271+
if lines.iter().filter(|l| l.trim().is_empty()).count() > 1 && !is_hidden_attr(attr) {
271272
span_lint(
272273
cx,
273274
EMPTY_LINE_AFTER_OUTER_ATTR,
@@ -312,6 +313,10 @@ fn check_semver(cx: &LateContext, span: Span, lit: &Lit) {
312313
);
313314
}
314315

316+
fn is_hidden_attr(attr: &Attribute) -> bool {
317+
attr.span.lo().to_usize() == 0 && attr.span.hi().to_usize() == 0
318+
}
319+
315320
fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
316321
if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node {
317322
mi.is_word() && mi.name() == expected

0 commit comments

Comments
 (0)