]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/usefulness/match-arm-statics-2.rs
Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup
[rust.git] / src / test / ui / pattern / usefulness / match-arm-statics-2.rs
1 use self::Direction::{North, East, South, West};
2
3 #[derive(PartialEq, Eq)]
4 struct NewBool(bool);
5
6 #[derive(PartialEq, Eq)]
7 enum Direction {
8     North,
9     East,
10     South,
11     West
12 }
13
14 const TRUE_TRUE: (bool, bool) = (true, true);
15
16 fn nonexhaustive_1() {
17     match (true, false) {
18     //~^ ERROR non-exhaustive patterns: `(true, false)` not covered
19         TRUE_TRUE => (),
20         (false, false) => (),
21         (false, true) => ()
22     }
23 }
24
25 const NONE: Option<Direction> = None;
26 const EAST: Direction = East;
27
28 fn nonexhaustive_2() {
29     match Some(Some(North)) {
30     //~^ ERROR non-exhaustive patterns: `Some(Some(West))` not covered
31         Some(NONE) => (),
32         Some(Some(North)) => (),
33         Some(Some(EAST)) => (),
34         Some(Some(South)) => (),
35         None => ()
36     }
37 }
38
39 const NEW_FALSE: NewBool = NewBool(false);
40 struct Foo {
41     bar: Option<Direction>,
42     baz: NewBool
43 }
44
45 const STATIC_FOO: Foo = Foo { bar: None, baz: NEW_FALSE };
46
47 fn nonexhaustive_3() {
48     match (Foo { bar: Some(North), baz: NewBool(true) }) {
49     //~^ ERROR non-exhaustive patterns: `Foo { bar: Some(North), baz: NewBool(true) }`
50         Foo { bar: None, baz: NewBool(true) } => (),
51         Foo { bar: _, baz: NEW_FALSE } => (),
52         Foo { bar: Some(West), baz: NewBool(true) } => (),
53         Foo { bar: Some(South), .. } => (),
54         Foo { bar: Some(EAST), .. } => ()
55     }
56 }
57
58 fn main() {
59     nonexhaustive_1();
60     nonexhaustive_2();
61     nonexhaustive_3();
62 }