diff --git a/.travis.yml b/.travis.yml index 7eaa61c5572..920aaf981f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ sudo: false script: - python util/update_lints.py -c - - cargo test + - cargo test --features debugging - bash util/dogfood.sh diff --git a/Cargo.toml b/Cargo.toml index b9ade2ac28f..c86b7b7d522 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.27" +version = "0.0.28" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -28,3 +28,4 @@ lazy_static = "*" [features] structured_logging = [] +debugging = [] diff --git a/src/cyclomatic_complexity.rs b/src/cyclomatic_complexity.rs index 678ebe866cb..1379a8db15d 100644 --- a/src/cyclomatic_complexity.rs +++ b/src/cyclomatic_complexity.rs @@ -44,17 +44,16 @@ impl CyclomaticComplexity { if narms > 0 { narms = narms - 1; } + if cc < narms { - println!("cc = {}, arms = {}", cc, narms); - println!("{:?}", block); - println!("{:?}", span); - panic!("cc = {}, arms = {}", cc, narms); - } - let rust_cc = cc - narms; - if rust_cc > self.limit.limit() { - cx.span_lint_help(CYCLOMATIC_COMPLEXITY, span, - &format!("The function has a cyclomatic complexity of {}.", rust_cc), - "You could split it up into multiple smaller functions"); + report_cc_bug(cx, cc, narms, span); + } else { + let rust_cc = cc - narms; + if rust_cc > self.limit.limit() { + cx.span_lint_help(CYCLOMATIC_COMPLEXITY, span, + &format!("The function has a cyclomatic complexity of {}.", rust_cc), + "You could split it up into multiple smaller functions"); + } } } } @@ -103,3 +102,17 @@ impl<'a> Visitor<'a> for MatchArmCounter { } } } + +#[cfg(feature="debugging")] +fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, span: Span) { + cx.sess().span_bug(span, &format!("Clippy encountered a bug calculating cyclomatic complexity: \ + cc = {}, arms = {}. Please file a bug report.", cc, narms));; +} +#[cfg(not(feature="debugging"))] +fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, span: Span) { + if cx.current_level(CYCLOMATIC_COMPLEXITY) != Level::Allow { + cx.sess().span_note(span, &format!("Clippy encountered a bug calculating cyclomatic complexity \ + (hide this message with `#[allow(cyclomatic_complexity)]`): \ + cc = {}, arms = {}. Please file a bug report.", cc, narms)); + } +}