rust/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

2019-11-30 15:51:26 +00:00
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![deny(unreachable_patterns)]
enum Foo {}
struct NonEmptyStruct(bool);
2019-12-03 14:07:14 +00:00
union NonEmptyUnion1 {
foo: (),
}
union NonEmptyUnion2 {
foo: (),
bar: (),
}
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
Foo(bool), //~ variant not covered
2019-11-30 15:51:26 +00:00
}
enum NonEmptyEnum2 { //~ `NonEmptyEnum2` defined here
Foo(bool), //~ variant not covered
Bar, //~ variant not covered
2019-11-30 15:51:26 +00:00
}
enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here
2019-11-30 15:51:26 +00:00
V1, V2, V3, V4, V5,
}
fn foo(x: Foo) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
}
}
fn main() {
match None::<!> {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
match None::<Foo> {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
match 0u8 {}
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
//~^ ERROR type `NonEmptyStruct` is non-empty
2019-12-03 14:07:14 +00:00
match (NonEmptyUnion1 { foo: () }) {}
//~^ ERROR type `NonEmptyUnion1` is non-empty
2019-12-03 14:07:14 +00:00
match (NonEmptyUnion2 { foo: () }) {}
//~^ ERROR type `NonEmptyUnion2` is non-empty
2019-11-30 15:51:26 +00:00
match NonEmptyEnum1::Foo(true) {}
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
2019-11-30 15:51:26 +00:00
match NonEmptyEnum2::Foo(true) {}
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
2019-11-30 15:51:26 +00:00
match NonEmptyEnum5::V1 {}
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
2019-11-30 15:51:26 +00:00
}