mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Make panic in CC silencable (partial #478)
This commit is contained in:
parent
5827240e17
commit
dc414e6c02
3 changed files with 26 additions and 12 deletions
|
@ -4,5 +4,5 @@ sudo: false
|
|||
|
||||
script:
|
||||
- python util/update_lints.py -c
|
||||
- cargo test
|
||||
- cargo test --features debugging
|
||||
- bash util/dogfood.sh
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "clippy"
|
||||
version = "0.0.27"
|
||||
version = "0.0.28"
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
"Andre Bogus <bogusandre@gmail.com>",
|
||||
|
@ -28,3 +28,4 @@ lazy_static = "*"
|
|||
[features]
|
||||
|
||||
structured_logging = []
|
||||
debugging = []
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue