2014-06-19 13:55:12 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-11-15 19:57:54 -06:00
|
|
|
#![feature(advanced_slice_patterns)]
|
2015-03-26 20:34:27 -05:00
|
|
|
#![feature(slice_patterns)]
|
2014-06-19 13:55:12 -05:00
|
|
|
|
|
|
|
struct Foo {
|
|
|
|
first: bool,
|
2015-01-08 05:02:42 -06:00
|
|
|
second: Option<[usize; 4]>
|
2014-06-19 13:55:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn struct_with_a_nested_enum_and_vector() {
|
2014-06-13 21:09:12 -05:00
|
|
|
match (Foo { first: true, second: None }) {
|
2014-07-07 13:54:50 -05:00
|
|
|
//~^ 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 } => (),
|
2015-03-03 02:42:26 -06:00
|
|
|
Foo { first: false, second: Some([1, 2, 3, 4]) } => ()
|
2014-06-19 13:55:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 05:13:40 -06:00
|
|
|
enum Color {
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn enum_with_two_missing_variants() {
|
2014-11-06 02:05:53 -06:00
|
|
|
match Color::Red {
|
2016-01-19 05:13:40 -06:00
|
|
|
//~^ ERROR non-exhaustive patterns: `Red` and `Green` not covered
|
2014-11-06 02:05:53 -06:00
|
|
|
Color::CustomRGBA { .. } => ()
|
2014-06-19 13:55:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 05:13:40 -06:00
|
|
|
enum Direction {
|
|
|
|
North, East, South, West
|
|
|
|
}
|
|
|
|
|
|
|
|
fn enum_with_three_or_more_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 `Sixth`, `Seventh`, `Eighth`, `Ninth`, `Tenth`, … and `Twelfth` not covered
|
|
|
|
|
|
|
|
ExcessiveEnum::First => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 13:55:12 -05:00
|
|
|
fn enum_struct_variant() {
|
2014-11-06 02:05:53 -06:00
|
|
|
match Color::Red {
|
2014-07-07 13:54:50 -05:00
|
|
|
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
|
2014-11-06 02:05:53 -06:00
|
|
|
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() {
|
2014-11-06 02:05:53 -06:00
|
|
|
let x: &'static [Enum] = &[Enum::First, Enum::Second(false)];
|
2014-06-19 13:55:12 -05:00
|
|
|
match x {
|
|
|
|
//~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
|
|
|
|
[] => (),
|
|
|
|
[_] => (),
|
2014-11-06 02:05:53 -06:00
|
|
|
[Enum::First, _] => (),
|
|
|
|
[Enum::Second(true), Enum::First] => (),
|
|
|
|
[Enum::Second(true), Enum::Second(true)] => (),
|
|
|
|
[Enum::Second(false), _] => (),
|
2014-09-06 17:23:55 -05:00
|
|
|
[_, _, tail.., _] => ()
|
2014-06-19 13:55:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 17:12:17 -05:00
|
|
|
fn missing_nil() {
|
|
|
|
match ((), false) {
|
|
|
|
//~^ ERROR non-exhaustive patterns: `((), false)` not covered
|
|
|
|
((), true) => ()
|
|
|
|
}
|
2014-06-13 21:09:12 -05:00
|
|
|
}
|
2014-06-23 17:12:17 -05:00
|
|
|
|
|
|
|
fn main() {}
|