Skip to content

Commit 4fa6f49

Browse files
committed
Merge pull request #764 from oli-obk/fix/cc/multi_diverge
prevent cc lint from panicking on unreachable code
2 parents eed9baa + d5a01e8 commit 4fa6f49

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/cyclomatic_complexity.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ impl CyclomaticComplexity {
4747
let cfg = CFG::new(cx.tcx, block);
4848
let n = cfg.graph.len_nodes() as u64;
4949
let e = cfg.graph.len_edges() as u64;
50+
if e + 2 < n {
51+
// the function has unreachable code, other lints should catch this
52+
return;
53+
}
5054
let cc = e + 2 - n;
5155
let mut helper = CCHelper {
5256
match_arms: 0,

tests/compile-fail/cyclomatic_complexity.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,9 @@ fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1
298298
}
299299
}
300300
}
301+
302+
#[cyclomatic_complexity = "0"]
303+
fn mcarton_sees_all() {
304+
panic!("meh");
305+
panic!("möh");
306+
}

0 commit comments

Comments
 (0)