1 #![deny(unreachable_patterns)]
2 #![feature(exhaustive_patterns)]
3 #![feature(never_type)]
6 pub enum UninhabitedEnum {
10 pub struct UninhabitedTupleStruct(!);
13 pub struct UninhabitedStruct {
17 pub enum UninhabitedVariants {
18 #[non_exhaustive] Tuple(!),
19 #[non_exhaustive] Struct { x: ! }
22 pub enum PartiallyInhabitedVariants {
24 #[non_exhaustive] Struct { x: ! }
27 fn uninhabited_enum() -> Option<UninhabitedEnum> {
31 fn uninhabited_variant() -> Option<UninhabitedVariants> {
35 fn partially_inhabited_variant() -> PartiallyInhabitedVariants {
36 PartiallyInhabitedVariants::Tuple(3)
39 fn uninhabited_struct() -> Option<UninhabitedStruct> {
43 fn uninhabited_tuple_struct() -> Option<UninhabitedTupleStruct> {
47 // This test checks that non-exhaustive types that would normally be considered uninhabited within
48 // the defining crate are still considered uninhabited.
51 match uninhabited_enum() {
52 Some(_x) => (), //~ ERROR unreachable pattern
56 match uninhabited_variant() {
57 Some(_x) => (), //~ ERROR unreachable pattern
61 while let PartiallyInhabitedVariants::Struct { x } = partially_inhabited_variant() {
62 //~^ ERROR unreachable pattern
65 while let Some(_x) = uninhabited_struct() { //~ ERROR unreachable pattern
68 while let Some(_x) = uninhabited_tuple_struct() { //~ ERROR unreachable pattern