]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs
d1e7c3b4d518a34768a92515eaae391a73e0bb49
[rust.git] / src / test / ui / rfc-2008-non-exhaustive / uninhabited / indirect_match_with_exhaustive_patterns_same_crate.rs
1 // check-pass
2
3 #![deny(unreachable_patterns)]
4 #![feature(exhaustive_patterns)]
5 #![feature(never_type)]
6 #![feature(non_exhaustive)]
7
8 #[non_exhaustive]
9 pub enum UninhabitedEnum {
10 }
11
12 #[non_exhaustive]
13 pub struct UninhabitedStruct {
14     _priv: !,
15 }
16
17 #[non_exhaustive]
18 pub struct UninhabitedTupleStruct(!);
19
20 pub enum UninhabitedVariants {
21     #[non_exhaustive] Tuple(!),
22     #[non_exhaustive] Struct { x: ! }
23 }
24
25 pub struct IndirectUninhabitedEnum(UninhabitedEnum);
26
27 pub struct IndirectUninhabitedStruct(UninhabitedStruct);
28
29 pub struct IndirectUninhabitedTupleStruct(UninhabitedTupleStruct);
30
31 pub struct IndirectUninhabitedVariants(UninhabitedVariants);
32
33 struct A;
34
35 // This test checks that an empty match on a non-exhaustive uninhabited type from the defining crate
36 // will compile. In particular, this enables the `exhaustive_patterns` feature as this can
37 // change the branch used in the compiler to determine this.
38 // Codegen is skipped because tests with long names can cause issues on Windows CI, see #60648.
39
40 fn cannot_empty_match_on_empty_enum_to_anything(x: IndirectUninhabitedEnum) -> A {
41     match x {}
42 }
43
44 fn cannot_empty_match_on_empty_struct_to_anything(x: IndirectUninhabitedStruct) -> A {
45     match x {}
46 }
47
48 fn cannot_empty_match_on_empty_tuple_struct_to_anything(x: IndirectUninhabitedTupleStruct) -> A {
49     match x {}
50 }
51
52 fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything(
53     x: IndirectUninhabitedVariants,
54 ) -> A {
55     match x {}
56 }
57
58 fn main() {}