]> git.lizzy.rs Git - rust.git/blob - src/test/ui/non-exhaustive/non-exhaustive-pattern-witness.rs
Simplify SaveHandler trait
[rust.git] / src / test / ui / non-exhaustive / non-exhaustive-pattern-witness.rs
1 #![feature(slice_patterns)]
2
3 struct Foo {
4     first: bool,
5     second: Option<[usize; 4]>
6 }
7
8 fn struct_with_a_nested_enum_and_vector() {
9     match (Foo { first: true, second: None }) {
10 //~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
11         Foo { first: true, second: None } => (),
12         Foo { first: true, second: Some(_) } => (),
13         Foo { first: false, second: None } => (),
14         Foo { first: false, second: Some([1, 2, 3, 4]) } => ()
15     }
16 }
17
18 enum Color {
19     Red,
20     Green,
21     CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
22 }
23
24 fn enum_with_single_missing_variant() {
25     match Color::Red {
26     //~^ ERROR non-exhaustive patterns: `Red` not covered
27         Color::CustomRGBA { .. } => (),
28         Color::Green => ()
29     }
30 }
31
32 enum Direction {
33     North, East, South, West
34 }
35
36 fn enum_with_multiple_missing_variants() {
37     match Direction::North {
38     //~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
39         Direction::North => ()
40     }
41 }
42
43 enum ExcessiveEnum {
44     First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth
45 }
46
47 fn enum_with_excessive_missing_variants() {
48     match ExcessiveEnum::First {
49     //~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
50
51         ExcessiveEnum::First => ()
52     }
53 }
54
55 fn enum_struct_variant() {
56     match Color::Red {
57     //~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
58         Color::Red => (),
59         Color::Green => (),
60         Color::CustomRGBA { a: false, r: _, g: _, b: 0 } => (),
61         Color::CustomRGBA { a: false, r: _, g: _, b: _ } => ()
62     }
63 }
64
65 enum Enum {
66     First,
67     Second(bool)
68 }
69
70 fn vectors_with_nested_enums() {
71     let x: &'static [Enum] = &[Enum::First, Enum::Second(false)];
72     match *x {
73     //~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
74         [] => (),
75         [_] => (),
76         [Enum::First, _] => (),
77         [Enum::Second(true), Enum::First] => (),
78         [Enum::Second(true), Enum::Second(true)] => (),
79         [Enum::Second(false), _] => (),
80         [_, _, ref tail.., _] => ()
81     }
82 }
83
84 fn missing_nil() {
85     match ((), false) {
86     //~^ ERROR non-exhaustive patterns: `((), false)` not covered
87         ((), true) => ()
88     }
89 }
90
91 fn main() {}