mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Merge pull request #1317 from oli-obk/cc_attr_used_fixed
mark cyclomatic complexity attribute as used
This commit is contained in:
commit
aa8ca9b607
@ -575,14 +575,14 @@ impl LimitStack {
|
||||
|
||||
fn parse_attrs<F: FnMut(u64)>(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");
|
||||
|
@ -4,7 +4,6 @@
|
||||
#![deny(cyclomatic_complexity)]
|
||||
#![allow(unused)]
|
||||
|
||||
|
||||
fn main() { //~ERROR the function has a cyclomatic complexity of 28
|
||||
if true {
|
||||
println!("a");
|
||||
|
17
tests/compile-fail/cyclomatic_complexity_attr_used.rs
Normal file
17
tests/compile-fail/cyclomatic_complexity_attr_used.rs
Normal file
@ -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?");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user