/
match-empty-exhaustive_patterns.rs
56 lines (52 loc) · 1.58 KB
/
match-empty-exhaustive_patterns.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![deny(unreachable_patterns)]
enum Foo {}
struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
union NonEmptyUnion1 {
foo: (),
}
union NonEmptyUnion2 {
foo: (),
bar: (),
}
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
Foo(bool), //~ variant not covered
}
enum NonEmptyEnum2 { //~ `NonEmptyEnum2` defined here
Foo(bool), //~ variant not covered
Bar, //~ variant not covered
}
enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here
V1, V2, V3, V4, V5,
}
fn foo(x: Foo) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
}
}
fn main() {
match None::<!> {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
match None::<Foo> {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
match 0u8 {}
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
//~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
match (NonEmptyUnion1 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
match (NonEmptyUnion2 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
match NonEmptyEnum1::Foo(true) {}
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
match NonEmptyEnum2::Foo(true) {}
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
match NonEmptyEnum5::V1 {}
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
}