Skip to content

Commit 2d57902

Browse files
committed
don't lint if snippet is shortert than 1 character
This happens with various combinations of cfg attributes and macros expansion. Not linting here is the safe route, as everything else might produce false positives.
1 parent 663d849 commit 2d57902

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

clippy_lints/src/attrs.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,16 @@ impl LateLintPass for AttrPass {
109109
if let MetaItemKind::List(ref name, _) = attr.node.value.node {
110110
match &**name {
111111
"allow" | "warn" | "deny" | "forbid" => {
112-
span_lint_and_then(cx, USELESS_ATTRIBUTE, attr.span,
113-
"useless lint attribute",
114-
|db| {
115-
if let Some(mut sugg) = snippet_opt(cx, attr.span) {
116-
sugg.insert(1, '!');
117-
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
112+
if let Some(mut sugg) = snippet_opt(cx, attr.span) {
113+
if sugg.len() > 1 {
114+
span_lint_and_then(cx, USELESS_ATTRIBUTE, attr.span,
115+
"useless lint attribute",
116+
|db| {
117+
sugg.insert(1, '!');
118+
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
119+
});
118120
}
119-
});
121+
}
120122
},
121123
_ => {},
122124
}

0 commit comments

Comments
 (0)