]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.rs
parser will not give wrong help message for 'public'
[rust.git] / src / test / ui / rfc-2008-non-exhaustive / uninhabited / patterns_same_crate.rs
1 #![deny(unreachable_patterns)]
2 #![feature(exhaustive_patterns)]
3 #![feature(never_type)]
4
5 #[non_exhaustive]
6 pub enum UninhabitedEnum {
7 }
8
9 #[non_exhaustive]
10 pub struct UninhabitedTupleStruct(!);
11
12 #[non_exhaustive]
13 pub struct UninhabitedStruct {
14     _priv: !,
15 }
16
17 pub enum UninhabitedVariants {
18     #[non_exhaustive] Tuple(!),
19     #[non_exhaustive] Struct { x: ! }
20 }
21
22 pub enum PartiallyInhabitedVariants {
23     Tuple(u8),
24     #[non_exhaustive] Struct { x: ! }
25 }
26
27 fn uninhabited_enum() -> Option<UninhabitedEnum> {
28     None
29 }
30
31 fn uninhabited_variant() -> Option<UninhabitedVariants> {
32     None
33 }
34
35 fn partially_inhabited_variant() -> PartiallyInhabitedVariants {
36     PartiallyInhabitedVariants::Tuple(3)
37 }
38
39 fn uninhabited_struct() -> Option<UninhabitedStruct> {
40     None
41 }
42
43 fn uninhabited_tuple_struct() -> Option<UninhabitedTupleStruct> {
44     None
45 }
46
47 // This test checks that non-exhaustive types that would normally be considered uninhabited within
48 // the defining crate are still considered uninhabited.
49
50 fn main() {
51     match uninhabited_enum() {
52         Some(_x) => (), //~ ERROR unreachable pattern
53         None => (),
54     }
55
56     match uninhabited_variant() {
57         Some(_x) => (), //~ ERROR unreachable pattern
58         None => (),
59     }
60
61     while let PartiallyInhabitedVariants::Struct { x } = partially_inhabited_variant() {
62         //~^ ERROR unreachable pattern
63     }
64
65     while let Some(_x) = uninhabited_struct() { //~ ERROR unreachable pattern
66     }
67
68     while let Some(_x) = uninhabited_tuple_struct() { //~ ERROR unreachable pattern
69     }
70 }