|
1 | 1 | // aux-build:uninhabited.rs |
2 | | -// compile-pass |
3 | | -#![deny(unreachable_patterns)] |
4 | | -#![feature(exhaustive_patterns)] |
| 2 | +#![feature(never_type)] |
5 | 3 |
|
6 | 4 | extern crate uninhabited; |
7 | 5 |
|
8 | 6 | use uninhabited::{ |
9 | | - PartiallyInhabitedVariants, |
10 | 7 | UninhabitedEnum, |
11 | 8 | UninhabitedStruct, |
12 | 9 | UninhabitedTupleStruct, |
13 | 10 | UninhabitedVariants, |
14 | 11 | }; |
15 | 12 |
|
16 | | -fn uninhabited_enum() -> Option<UninhabitedEnum> { |
17 | | - None |
18 | | -} |
| 13 | +// This test checks that uninhabited non-exhaustive types cannot coerce to any type, as the never |
| 14 | +// type can. |
19 | 15 |
|
20 | | -fn uninhabited_variant() -> Option<UninhabitedVariants> { |
21 | | - None |
22 | | -} |
| 16 | +struct A; |
23 | 17 |
|
24 | | -fn partially_inhabited_variant() -> PartiallyInhabitedVariants { |
25 | | - PartiallyInhabitedVariants::Tuple(3) |
| 18 | +fn can_coerce_never_type_to_anything(x: !) -> A { |
| 19 | + x |
26 | 20 | } |
27 | 21 |
|
28 | | -fn uninhabited_struct() -> Option<UninhabitedStruct> { |
29 | | - None |
| 22 | +fn cannot_coerce_empty_enum_to_anything(x: UninhabitedEnum) -> A { |
| 23 | + x //~ ERROR mismatched types |
30 | 24 | } |
31 | 25 |
|
32 | | -fn uninhabited_tuple_struct() -> Option<UninhabitedTupleStruct> { |
33 | | - None |
| 26 | +fn cannot_coerce_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A { |
| 27 | + x //~ ERROR mismatched types |
34 | 28 | } |
35 | 29 |
|
36 | | -// This test checks that non-exhaustive types that would normally be considered uninhabited within |
37 | | -// the defining crate are not considered uninhabited from extern crates. |
38 | | - |
39 | | -fn main() { |
40 | | - match uninhabited_enum() { |
41 | | - Some(_x) => (), // This line would normally error. |
42 | | - None => (), |
43 | | - } |
44 | | - |
45 | | - match uninhabited_variant() { |
46 | | - Some(_x) => (), // This line would normally error. |
47 | | - None => (), |
48 | | - } |
49 | | - |
50 | | - // This line would normally error. |
51 | | - while let PartiallyInhabitedVariants::Struct { x, .. } = partially_inhabited_variant() { |
52 | | - } |
53 | | - |
54 | | - while let Some(_x) = uninhabited_struct() { // This line would normally error. |
55 | | - } |
| 30 | +fn cannot_coerce_empty_struct_to_anything(x: UninhabitedStruct) -> A { |
| 31 | + x //~ ERROR mismatched types |
| 32 | +} |
56 | 33 |
|
57 | | - while let Some(_x) = uninhabited_tuple_struct() { // This line would normally error. |
58 | | - } |
| 34 | +fn cannot_coerce_enum_with_empty_variants_to_anything(x: UninhabitedVariants) -> A { |
| 35 | + x //~ ERROR mismatched types |
59 | 36 | } |
| 37 | + |
| 38 | +fn main() {} |
0 commit comments