Skip to content

Commit

Permalink
Add workaround for hidden outer attribute
Browse files Browse the repository at this point in the history
If the snippet is empty, it's an attribute that was inserted during macro
expansion and we want to ignore those, because they could come from external
sources that the user has no control over.
For some reason these attributes don't have any expansion info on them, so
we have to check it this way until there is a better way.
  • Loading branch information
phansch committed Jan 29, 2018
1 parent aade0d5 commit 3d54e56
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {

for attr in attrs {
if attr.style == AttrStyle::Outer {
if !is_present_in_source(cx, attr.span) {
return;
}

let attr_to_item_span = Span::new(attr.span.lo(), span.lo(), span.ctxt());

if let Some(snippet) = snippet_opt(cx, attr_to_item_span) {
Expand Down Expand Up @@ -319,3 +323,17 @@ fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
false
}
}

// If the snippet is empty, it's an attribute that was inserted during macro
// expansion and we want to ignore those, because they could come from external
// sources that the user has no control over.
// For some reason these attributes don't have any expansion info on them, so
// we have to check it this way until there is a better way.
fn is_present_in_source(cx: &LateContext, span: Span) -> bool {
if let Some(snippet) = snippet_opt(cx, span) {
if snippet.is_empty() {
return false;
}
}
true
}

0 comments on commit 3d54e56

Please sign in to comment.