From d5a01e8789ff46e4f35bf48273c274b5c5effd31 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 14 Mar 2016 17:24:55 +0100 Subject: [PATCH] prevent cc lint from panicking on unreachable code --- src/cyclomatic_complexity.rs | 4 ++++ tests/compile-fail/cyclomatic_complexity.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/cyclomatic_complexity.rs b/src/cyclomatic_complexity.rs index bc13576fe3b..a03a42f2bc0 100644 --- a/src/cyclomatic_complexity.rs +++ b/src/cyclomatic_complexity.rs @@ -47,6 +47,10 @@ impl CyclomaticComplexity { let cfg = CFG::new(cx.tcx, block); let n = cfg.graph.len_nodes() as u64; let e = cfg.graph.len_edges() as u64; + if e + 2 < n { + // the function has unreachable code, other lints should catch this + return; + } let cc = e + 2 - n; let mut helper = CCHelper { match_arms: 0, diff --git a/tests/compile-fail/cyclomatic_complexity.rs b/tests/compile-fail/cyclomatic_complexity.rs index 30a05c3f87d..f744d60440f 100644 --- a/tests/compile-fail/cyclomatic_complexity.rs +++ b/tests/compile-fail/cyclomatic_complexity.rs @@ -298,3 +298,9 @@ fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1 } } } + +#[cyclomatic_complexity = "0"] +fn mcarton_sees_all() { + panic!("meh"); + panic!("möh"); +}