From 2d57902a27d09f327670e9ae3001e1d27aba5352 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 18 Aug 2016 11:08:35 +0200 Subject: [PATCH] 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. --- clippy_lints/src/attrs.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 014ace0fb45f..4bb32ec4d327 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -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); + }); } - }); + } }, _ => {}, }