]> git.proxmox.com Git - rustc.git/blame - src/test/ui/rfc-2008-non-exhaustive/uninhabited/coercions_same_crate.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / rfc-2008-non-exhaustive / uninhabited / coercions_same_crate.rs
CommitLineData
48663c56 1#![feature(never_type)]
48663c56
XL
2
3#[non_exhaustive]
4pub enum UninhabitedEnum {
5}
6
7#[non_exhaustive]
8pub struct UninhabitedTupleStruct(!);
9
10#[non_exhaustive]
11pub struct UninhabitedStruct {
12 _priv: !,
13}
14
15pub enum UninhabitedVariants {
16 #[non_exhaustive] Tuple(!),
17 #[non_exhaustive] Struct { x: ! }
18}
19
20struct 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
25fn can_coerce_never_type_to_anything(x: !) -> A {
26 x
27}
28
29fn cannot_coerce_empty_enum_to_anything(x: UninhabitedEnum) -> A {
30 x //~ ERROR mismatched types
31}
32
33fn cannot_coerce_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A {
34 x //~ ERROR mismatched types
35}
36
37fn cannot_coerce_empty_struct_to_anything(x: UninhabitedStruct) -> A {
38 x //~ ERROR mismatched types
39}
40
41fn cannot_coerce_enum_with_empty_variants_to_anything(x: UninhabitedVariants) -> A {
42 x //~ ERROR mismatched types
43}
44
45fn main() {}