Skip to content

prevent cc lint from panicking on unreachable code #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests/compile-fail/cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,9 @@ fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1
}
}
}

#[cyclomatic_complexity = "0"]
fn mcarton_sees_all() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

panic!("meh");
panic!("möh");
}