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