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