]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match-arm-statics.rs
Rollup merge of #61389 - Zoxc:arena-cleanup, r=eddyb
[rust.git] / src / test / ui / match / match-arm-statics.rs
1 #![allow(dead_code)]
2 #![deny(unreachable_patterns)]
3
4 use self::Direction::{North, East, South, West};
5
6 #[derive(PartialEq, Eq)]
7 struct NewBool(bool);
8
9 #[derive(PartialEq, Eq)]
10 enum Direction {
11     North,
12     East,
13     South,
14     West
15 }
16
17 const TRUE_TRUE: (bool, bool) = (true, true);
18
19 fn unreachable_1() {
20     match (true, false) {
21         TRUE_TRUE => (),
22         (false, false) => (),
23         (false, true) => (),
24         (true, false) => (),
25         (true, true) => ()
26         //~^ ERROR unreachable pattern
27     }
28 }
29
30 const NONE: Option<Direction> = None;
31 const EAST: Direction = East;
32
33 fn unreachable_2() {
34     match Some(Some(North)) {
35         Some(NONE) => (),
36         Some(Some(North)) => (),
37         Some(Some(EAST)) => (),
38         Some(Some(South)) => (),
39         Some(Some(West)) => (),
40         Some(Some(East)) => (),
41         //~^ ERROR unreachable pattern
42         None => ()
43     }
44 }
45
46 const NEW_FALSE: NewBool = NewBool(false);
47 struct Foo {
48     bar: Option<Direction>,
49     baz: NewBool
50 }
51
52 fn unreachable_3() {
53     match (Foo { bar: Some(EAST), baz: NewBool(true) }) {
54         Foo { bar: None, baz: NewBool(true) } => (),
55         Foo { bar: _, baz: NEW_FALSE } => (),
56         Foo { bar: Some(West), baz: NewBool(true) } => (),
57         Foo { bar: Some(South), .. } => (),
58         Foo { bar: Some(EAST), .. } => (),
59         Foo { bar: Some(North), baz: NewBool(true) } => (),
60         Foo { bar: Some(EAST), baz: NewBool(false) } => ()
61         //~^ ERROR unreachable pattern
62     }
63 }
64
65 fn main() {
66     unreachable_1();
67     unreachable_2();
68     unreachable_3();
69 }