rust-clippy/tests/cc_seme.rs
Oliver Schneider 902c7d832b fix cc computation in the presence of diverging calls
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.
2015-12-14 14:29:20 +01:00

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!(),
}
}