mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
902c7d832b
CFG treats diverging calls as its completely own path out of the function. While this makes sense, it should also mean that a panic should increase the cyclomatic complexity. Instead it decreases it. Minimal example: ```rust if a { b } else { panic!("cake"); } d ``` creates the following graph ```dot digraph G { "if a" -> "b" "if a" -> "panic!(\"cake\")" "b" -> c } ``` which has a CC of 1 (3 - 4 + 2). A CC of 1 means there is one path through the program. Obviously that is wrong. There are two paths. One returning normally, and one panicking.
25 lines
438 B
Rust
25 lines
438 B
Rust
#![feature(plugin)]
|
|
#![plugin(clippy)]
|
|
|
|
#[allow(dead_code)]
|
|
enum Baz {
|
|
Baz1,
|
|
Baz2,
|
|
}
|
|
|
|
struct Test {
|
|
t: Option<usize>,
|
|
b: Baz,
|
|
}
|
|
|
|
fn main() {
|
|
use Baz::*;
|
|
let x = Test { t: Some(0), b: Baz1 };
|
|
|
|
match x {
|
|
Test { t: Some(_), b: Baz1 } => unreachable!(),
|
|
Test { t: Some(42), b: Baz2 } => unreachable!(),
|
|
Test { t: None, .. } => unreachable!(),
|
|
Test { .. } => unreachable!(),
|
|
}
|
|
}
|