]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/non-exhaustive-pattern-witness.rs
auto merge of #15518 : alexcrichton/rust/fix-some-crate-names, r=sfackler
[rust.git] / src / test / compile-fail / non-exhaustive-pattern-witness.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(struct_variant)]
12
13 struct Foo {
14     first: bool,
15     second: Option<[uint, ..4]>
16 }
17
18 enum Color {
19     Red,
20     Green,
21     CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
22 }
23
24 fn struct_with_a_nested_enum_and_vector() {
25     match (Foo { first: true, second: None }) {
26 //~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
27         Foo { first: true, second: None } => (),
28         Foo { first: true, second: Some(_) } => (),
29         Foo { first: false, second: None } => (),
30         Foo { first: false, second: Some([1u, 2u, 3u, 4u]) } => ()
31     }
32 }
33
34 fn enum_with_multiple_missing_variants() {
35     match Red {
36     //~^ ERROR non-exhaustive patterns: `Red` not covered
37         CustomRGBA { .. } => ()
38     }
39 }
40
41 fn enum_struct_variant() {
42     match Red {
43     //~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
44         Red => (),
45         Green => (),
46         CustomRGBA { a: false, r: _, g: _, b: 0 } => (),
47         CustomRGBA { a: false, r: _, g: _, b: _ } => ()
48     }
49 }
50
51 enum Enum {
52     First,
53     Second(bool)
54 }
55
56 fn vectors_with_nested_enums() {
57     let x: &'static [Enum] = [First, Second(false)];
58     match x {
59     //~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
60         [] => (),
61         [_] => (),
62         [First, _] => (),
63         [Second(true), First] => (),
64         [Second(true), Second(true)] => (),
65         [Second(false), _] => (),
66         [_, _, ..tail, _] => ()
67     }
68 }
69
70 fn missing_nil() {
71     match ((), false) {
72     //~^ ERROR non-exhaustive patterns: `((), false)` not covered
73         ((), true) => ()
74     }
75 }
76
77 fn main() {}