]> git.proxmox.com Git - rustc.git/blob - src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / pattern / usefulness / match-empty-exhaustive_patterns.rs
1 #![feature(never_type)]
2 #![feature(exhaustive_patterns)]
3 #![deny(unreachable_patterns)]
4 enum Foo {}
5
6 struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
7 union NonEmptyUnion1 { //~ `NonEmptyUnion1` defined here
8 foo: (),
9 }
10 union NonEmptyUnion2 { //~ `NonEmptyUnion2` defined here
11 foo: (),
12 bar: (),
13 }
14 enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
15 Foo(bool),
16 //~^ not covered
17 //~| not covered
18 }
19 enum NonEmptyEnum2 { //~ `NonEmptyEnum2` defined here
20 Foo(bool),
21 //~^ not covered
22 //~| not covered
23 Bar,
24 //~^ not covered
25 //~| not covered
26 }
27 enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here
28 V1, V2, V3, V4, V5,
29 }
30
31 macro_rules! match_empty {
32 ($e:expr) => {
33 match $e {}
34 };
35 }
36 macro_rules! match_false {
37 ($e:expr) => {
38 match $e {
39 _ if false => {}
40 }
41 };
42 }
43
44 fn foo(x: Foo) {
45 match_empty!(x); // ok
46 match x {
47 _ => {}, //~ ERROR unreachable pattern
48 }
49 match x {
50 _ if false => {}, //~ ERROR unreachable pattern
51 }
52 }
53
54 fn main() {
55 match None::<!> {
56 None => {}
57 Some(_) => {} //~ ERROR unreachable pattern
58 }
59 match None::<Foo> {
60 None => {}
61 Some(_) => {} //~ ERROR unreachable pattern
62 }
63
64 match_empty!(0u8);
65 //~^ ERROR type `u8` is non-empty
66 match_empty!(NonEmptyStruct(true));
67 //~^ ERROR type `NonEmptyStruct` is non-empty
68 match_empty!((NonEmptyUnion1 { foo: () }));
69 //~^ ERROR type `NonEmptyUnion1` is non-empty
70 match_empty!((NonEmptyUnion2 { foo: () }));
71 //~^ ERROR type `NonEmptyUnion2` is non-empty
72 match_empty!(NonEmptyEnum1::Foo(true));
73 //~^ ERROR `Foo(_)` not covered
74 match_empty!(NonEmptyEnum2::Foo(true));
75 //~^ ERROR `Foo(_)` and `Bar` not covered
76 match_empty!(NonEmptyEnum5::V1);
77 //~^ ERROR `V1`, `V2`, `V3` and 2 more not covered
78
79 match_false!(0u8);
80 //~^ ERROR `_` not covered
81 match_false!(NonEmptyStruct(true));
82 //~^ ERROR `NonEmptyStruct(_)` not covered
83 match_false!((NonEmptyUnion1 { foo: () }));
84 //~^ ERROR `NonEmptyUnion1 { .. }` not covered
85 match_false!((NonEmptyUnion2 { foo: () }));
86 //~^ ERROR `NonEmptyUnion2 { .. }` not covered
87 match_false!(NonEmptyEnum1::Foo(true));
88 //~^ ERROR `Foo(_)` not covered
89 match_false!(NonEmptyEnum2::Foo(true));
90 //~^ ERROR `Foo(_)` and `Bar` not covered
91 match_false!(NonEmptyEnum5::V1);
92 //~^ ERROR `V1`, `V2`, `V3` and 2 more not covered
93 }