]>
Commit | Line | Data |
---|---|---|
48663c56 | 1 | #![feature(never_type)] |
48663c56 XL |
2 | |
3 | #[non_exhaustive] | |
4 | pub enum UninhabitedEnum { | |
5 | } | |
6 | ||
7 | #[non_exhaustive] | |
8 | pub struct UninhabitedTupleStruct(!); | |
9 | ||
10 | #[non_exhaustive] | |
11 | pub struct UninhabitedStruct { | |
12 | _priv: !, | |
13 | } | |
14 | ||
15 | pub enum UninhabitedVariants { | |
16 | #[non_exhaustive] Tuple(!), | |
17 | #[non_exhaustive] Struct { x: ! } | |
18 | } | |
19 | ||
20 | struct A; | |
21 | ||
22 | // This test checks that uninhabited non-exhaustive types defined in the same crate cannot coerce | |
23 | // to any type, as the never type can. | |
24 | ||
25 | fn can_coerce_never_type_to_anything(x: !) -> A { | |
26 | x | |
27 | } | |
28 | ||
29 | fn cannot_coerce_empty_enum_to_anything(x: UninhabitedEnum) -> A { | |
30 | x //~ ERROR mismatched types | |
31 | } | |
32 | ||
33 | fn cannot_coerce_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A { | |
34 | x //~ ERROR mismatched types | |
35 | } | |
36 | ||
37 | fn cannot_coerce_empty_struct_to_anything(x: UninhabitedStruct) -> A { | |
38 | x //~ ERROR mismatched types | |
39 | } | |
40 | ||
41 | fn cannot_coerce_enum_with_empty_variants_to_anything(x: UninhabitedVariants) -> A { | |
42 | x //~ ERROR mismatched types | |
43 | } | |
44 | ||
45 | fn main() {} |