Skip to content

Commit b956c4d

Browse files
committed
Add workaround for hidden outer attribute
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.
1 parent eaee569 commit b956c4d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

clippy_lints/src/attrs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
263263

264264
for attr in attrs {
265265
if attr.style == AttrStyle::Outer {
266+
if !is_present_in_source(cx, attr.span) {
267+
return;
268+
}
269+
266270
let attr_to_item_span = Span::new(attr.span.lo(), span.lo(), span.ctxt());
267271

268272
if let Some(snippet) = snippet_opt(cx, attr_to_item_span) {
@@ -319,3 +323,17 @@ fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
319323
false
320324
}
321325
}
326+
327+
// If the snippet is empty, it's an attribute that was inserted during macro
328+
// expansion and we want to ignore those, because they could come from external
329+
// sources that the user has no control over.
330+
// For some reason these attributes don't have any expansion info on them, so
331+
// we have to check it this way until there is a better way.
332+
fn is_present_in_source(cx: &LateContext, span: Span) -> bool {
333+
if let Some(snippet) = snippet_opt(cx, span) {
334+
if snippet.is_empty() {
335+
return false;
336+
}
337+
}
338+
return true
339+
}

0 commit comments

Comments
 (0)