rust/src/test/ui/non-exhaustive/non-exhaustive-pattern-witness.rs

92 lines
2.3 KiB
Rust
Raw Normal View History

#![feature(slice_patterns)]
2014-06-19 13:55:12 -05:00
struct Foo {
first: bool,
second: Option<[usize; 4]>
2014-06-19 13:55:12 -05:00
}
fn struct_with_a_nested_enum_and_vector() {
match (Foo { first: true, second: None }) {
//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
2014-06-19 13:55:12 -05:00
Foo { first: true, second: None } => (),
Foo { first: true, second: Some(_) } => (),
Foo { first: false, second: None } => (),
Foo { first: false, second: Some([1, 2, 3, 4]) } => ()
2014-06-19 13:55:12 -05:00
}
}
enum Color {
Red,
Green,
CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
}
fn enum_with_single_missing_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `Red` not covered
Color::CustomRGBA { .. } => (),
Color::Green => ()
2014-06-19 13:55:12 -05:00
}
}
enum Direction {
North, East, South, West
}
fn enum_with_multiple_missing_variants() {
match Direction::North {
//~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
Direction::North => ()
}
}
enum ExcessiveEnum {
First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth
}
fn enum_with_excessive_missing_variants() {
match ExcessiveEnum::First {
//~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
ExcessiveEnum::First => ()
}
}
2014-06-19 13:55:12 -05:00
fn enum_struct_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
Color::Red => (),
Color::Green => (),
Color::CustomRGBA { a: false, r: _, g: _, b: 0 } => (),
Color::CustomRGBA { a: false, r: _, g: _, b: _ } => ()
2014-06-19 13:55:12 -05:00
}
}
enum Enum {
First,
Second(bool)
}
fn vectors_with_nested_enums() {
let x: &'static [Enum] = &[Enum::First, Enum::Second(false)];
match *x {
2014-06-19 13:55:12 -05:00
//~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
[] => (),
[_] => (),
[Enum::First, _] => (),
[Enum::Second(true), Enum::First] => (),
[Enum::Second(true), Enum::Second(true)] => (),
[Enum::Second(false), _] => (),
[_, _, ref tail.., _] => ()
2014-06-19 13:55:12 -05:00
}
}
fn missing_nil() {
match ((), false) {
//~^ ERROR non-exhaustive patterns: `((), false)` not covered
((), true) => ()
}
}
fn main() {}