diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index edb0f1cf1d3..276ff8f065e 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -575,14 +575,14 @@ impl LimitStack { fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &'static str, mut f: F) { for attr in attrs { - let attr = &attr.node; - if attr.is_sugared_doc { + if attr.node.is_sugared_doc { continue; } - if let ast::MetaItemKind::NameValue(ref key, ref value) = attr.value.node { + if let ast::MetaItemKind::NameValue(ref key, ref value) = attr.node.value.node { if *key == name { if let LitKind::Str(ref s, _) = value.node { if let Ok(value) = FromStr::from_str(s) { + attr::mark_used(attr); f(value) } else { sess.span_err(value.span, "not a number"); diff --git a/tests/compile-fail/cyclomatic_complexity.rs b/tests/compile-fail/cyclomatic_complexity.rs index 2160272bf46..655420d5be3 100644 --- a/tests/compile-fail/cyclomatic_complexity.rs +++ b/tests/compile-fail/cyclomatic_complexity.rs @@ -4,7 +4,6 @@ #![deny(cyclomatic_complexity)] #![allow(unused)] - fn main() { //~ERROR the function has a cyclomatic complexity of 28 if true { println!("a"); diff --git a/tests/compile-fail/cyclomatic_complexity_attr_used.rs b/tests/compile-fail/cyclomatic_complexity_attr_used.rs new file mode 100644 index 00000000000..f322a7b51da --- /dev/null +++ b/tests/compile-fail/cyclomatic_complexity_attr_used.rs @@ -0,0 +1,17 @@ +#![feature(plugin, custom_attribute)] +#![plugin(clippy)] +#![deny(cyclomatic_complexity)] +#![deny(unused)] + +fn main() { + kaboom(); +} + +#[cyclomatic_complexity = "0"] +fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 3 + if 42 == 43 { + panic!(); + } else if "cake" == "lie" { + println!("what?"); + } +}