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.
This commit is contained in:
Oliver Schneider 2016-08-18 11:08:35 +02:00
parent 663d8497aa
commit 2d57902a27
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46

View File

@ -109,14 +109,16 @@ impl LateLintPass for AttrPass {
if let MetaItemKind::List(ref name, _) = attr.node.value.node {
match &**name {
"allow" | "warn" | "deny" | "forbid" => {
span_lint_and_then(cx, USELESS_ATTRIBUTE, attr.span,
"useless lint attribute",
|db| {
if let Some(mut sugg) = snippet_opt(cx, attr.span) {
sugg.insert(1, '!');
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
if let Some(mut sugg) = snippet_opt(cx, attr.span) {
if sugg.len() > 1 {
span_lint_and_then(cx, USELESS_ATTRIBUTE, attr.span,
"useless lint attribute",
|db| {
sugg.insert(1, '!');
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
});
}
});
}
},
_ => {},
}