]> git.proxmox.com Git - rustc.git/blob - tests/ui/rfc-2008-non-exhaustive/uninhabited/coercions.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / rfc-2008-non-exhaustive / uninhabited / coercions.rs
1 // aux-build:uninhabited.rs
2 #![feature(never_type)]
3
4 extern crate uninhabited;
5
6 use uninhabited::{
7 UninhabitedEnum,
8 UninhabitedStruct,
9 UninhabitedTupleStruct,
10 UninhabitedVariants,
11 };
12
13 // This test checks that uninhabited non-exhaustive types cannot coerce to any type, as the never
14 // type can.
15
16 struct A;
17
18 fn can_coerce_never_type_to_anything(x: !) -> A {
19 x
20 }
21
22 fn cannot_coerce_empty_enum_to_anything(x: UninhabitedEnum) -> A {
23 x //~ ERROR mismatched types
24 }
25
26 fn cannot_coerce_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A {
27 x //~ ERROR mismatched types
28 }
29
30 fn cannot_coerce_empty_struct_to_anything(x: UninhabitedStruct) -> A {
31 x //~ ERROR mismatched types
32 }
33
34 fn cannot_coerce_enum_with_empty_variants_to_anything(x: UninhabitedVariants) -> A {
35 x //~ ERROR mismatched types
36 }
37
38 fn main() {}