2020-11-16 15:13:00 -06:00
|
|
|
// aux-build:empty.rs
|
2020-12-02 14:24:20 -06:00
|
|
|
// revisions: normal exhaustive_patterns
|
2020-12-02 17:11:29 -06:00
|
|
|
//
|
|
|
|
// This tests a match with no arms on various types.
|
2019-11-30 09:51:26 -06:00
|
|
|
#![feature(never_type)]
|
2020-11-12 11:24:42 -06:00
|
|
|
#![feature(never_type_fallback)]
|
2020-12-02 14:24:20 -06:00
|
|
|
#![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))]
|
2019-11-30 09:51:26 -06:00
|
|
|
#![deny(unreachable_patterns)]
|
2020-11-16 15:13:00 -06:00
|
|
|
|
|
|
|
extern crate empty;
|
|
|
|
|
|
|
|
enum EmptyEnum {}
|
2019-11-30 09:51:26 -06:00
|
|
|
|
2020-12-02 17:11:29 -06:00
|
|
|
struct NonEmptyStruct1;
|
|
|
|
struct NonEmptyStruct2(bool);
|
|
|
|
union NonEmptyUnion1 {
|
2019-12-03 08:07:14 -06:00
|
|
|
foo: (),
|
|
|
|
}
|
2020-12-02 17:11:29 -06:00
|
|
|
union NonEmptyUnion2 {
|
2019-12-03 08:07:14 -06:00
|
|
|
foo: (),
|
|
|
|
bar: (),
|
|
|
|
}
|
2020-12-02 17:11:29 -06:00
|
|
|
enum NonEmptyEnum1 {
|
2019-12-03 10:15:25 -06:00
|
|
|
Foo(bool),
|
2019-11-30 09:51:26 -06:00
|
|
|
}
|
2020-12-02 17:11:29 -06:00
|
|
|
enum NonEmptyEnum2 {
|
2019-12-03 10:15:25 -06:00
|
|
|
Foo(bool),
|
|
|
|
Bar,
|
2019-11-30 09:51:26 -06:00
|
|
|
}
|
2020-12-02 17:11:29 -06:00
|
|
|
enum NonEmptyEnum5 {
|
2019-11-30 09:51:26 -06:00
|
|
|
V1, V2, V3, V4, V5,
|
|
|
|
}
|
|
|
|
|
2020-11-16 15:13:00 -06:00
|
|
|
fn empty_enum(x: EmptyEnum) {
|
|
|
|
match x {} // ok
|
|
|
|
match x {
|
|
|
|
_ => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
_ if false => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
|
2020-11-12 11:24:42 -06:00
|
|
|
match x {} // ok
|
|
|
|
match x {
|
|
|
|
_ => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
_ if false => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn never(x: !) {
|
|
|
|
match x {} // ok
|
2019-11-30 09:51:26 -06:00
|
|
|
match x {
|
|
|
|
_ => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
2019-12-03 09:57:04 -06:00
|
|
|
match x {
|
|
|
|
_ if false => {}, //~ ERROR unreachable pattern
|
|
|
|
}
|
2019-11-30 09:51:26 -06:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:11:29 -06:00
|
|
|
macro_rules! match_no_arms {
|
|
|
|
($e:expr) => {
|
|
|
|
match $e {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
macro_rules! match_guarded_arm {
|
|
|
|
($e:expr) => {
|
|
|
|
match $e {
|
|
|
|
_ if false => {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-11-30 09:51:26 -06:00
|
|
|
|
2020-12-02 17:11:29 -06:00
|
|
|
fn main() {
|
|
|
|
match_no_arms!(0u8); //~ ERROR type `u8` is non-empty
|
|
|
|
match_no_arms!(NonEmptyStruct1); //~ ERROR type `NonEmptyStruct1` is non-empty
|
|
|
|
match_no_arms!(NonEmptyStruct2(true)); //~ ERROR type `NonEmptyStruct2` is non-empty
|
|
|
|
match_no_arms!((NonEmptyUnion1 { foo: () })); //~ ERROR type `NonEmptyUnion1` is non-empty
|
|
|
|
match_no_arms!((NonEmptyUnion2 { foo: () })); //~ ERROR type `NonEmptyUnion2` is non-empty
|
|
|
|
match_no_arms!(NonEmptyEnum1::Foo(true)); //~ ERROR `Foo(_)` not covered
|
|
|
|
match_no_arms!(NonEmptyEnum2::Foo(true)); //~ ERROR `Foo(_)` and `Bar` not covered
|
|
|
|
match_no_arms!(NonEmptyEnum5::V1); //~ ERROR `V1`, `V2`, `V3` and 2 more not covered
|
2019-12-03 09:57:04 -06:00
|
|
|
|
2020-12-02 17:11:29 -06:00
|
|
|
match_guarded_arm!(0u8); //~ ERROR `_` not covered
|
|
|
|
match_guarded_arm!(NonEmptyStruct1); //~ ERROR `NonEmptyStruct1` not covered
|
|
|
|
match_guarded_arm!(NonEmptyStruct2(true)); //~ ERROR `NonEmptyStruct2(_)` not covered
|
|
|
|
match_guarded_arm!((NonEmptyUnion1 { foo: () })); //~ ERROR `NonEmptyUnion1 { .. }` not covered
|
|
|
|
match_guarded_arm!((NonEmptyUnion2 { foo: () })); //~ ERROR `NonEmptyUnion2 { .. }` not covered
|
|
|
|
match_guarded_arm!(NonEmptyEnum1::Foo(true)); //~ ERROR `Foo(_)` not covered
|
|
|
|
match_guarded_arm!(NonEmptyEnum2::Foo(true)); //~ ERROR `Foo(_)` and `Bar` not covered
|
|
|
|
match_guarded_arm!(NonEmptyEnum5::V1); //~ ERROR `V1`, `V2`, `V3` and 2 more not covered
|
2019-11-30 09:51:26 -06:00
|
|
|
}
|