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