]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/non-exhaustive-match.rs
Imported Upstream version 1.0.0~0alpha
[rustc.git] / src / test / compile-fail / non-exhaustive-match.rs
CommitLineData
223e47cc
LB
1// Copyright 2012 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
11enum t { a, b, }
12
13fn main() {
1a4d82fc
JJ
14 let x = t::a;
15 match x { t::b => { } } //~ ERROR non-exhaustive patterns: `a` not covered
16 match true { //~ ERROR non-exhaustive patterns: `false` not covered
223e47cc
LB
17 true => {}
18 }
1a4d82fc
JJ
19 match Some(10is) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
20 None => {}
223e47cc 21 }
1a4d82fc 22 match (2is, 3is, 4is) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered
223e47cc
LB
23 (_, _, 4) => {}
24 }
1a4d82fc
JJ
25 match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered
26 (t::a, t::b) => {}
27 (t::b, t::a) => {}
223e47cc 28 }
1a4d82fc
JJ
29 match t::a { //~ ERROR non-exhaustive patterns: `b` not covered
30 t::a => {}
223e47cc
LB
31 }
32 // This is exhaustive, though the algorithm got it wrong at one point
1a4d82fc
JJ
33 match (t::a, t::b) {
34 (t::a, _) => {}
35 (_, t::a) => {}
36 (t::b, t::b) => {}
37 }
38 let vec = vec!(Some(42is), None, Some(21is));
39 let vec: &[Option<isize>] = vec.as_slice();
40 match vec { //~ ERROR non-exhaustive patterns: `[]` not covered
41 [Some(..), None, tail..] => {}
42 [Some(..), Some(..), tail..] => {}
223e47cc
LB
43 [None] => {}
44 }
1a4d82fc
JJ
45 let vec = vec!(1is);
46 let vec: &[isize] = vec.as_slice();
47 match vec {
48 [_, tail..] => (),
223e47cc
LB
49 [] => ()
50 }
1a4d82fc
JJ
51 let vec = vec!(0.5f32);
52 let vec: &[f32] = vec.as_slice();
53 match vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
223e47cc
LB
54 [0.1, 0.2, 0.3] => (),
55 [0.1, 0.2] => (),
56 [0.1] => (),
57 [] => ()
58 }
1a4d82fc
JJ
59 let vec = vec!(Some(42is), None, Some(21is));
60 let vec: &[Option<isize>] = vec.as_slice();
61 match vec {
62 [Some(..), None, tail..] => {}
63 [Some(..), Some(..), tail..] => {}
64 [None, None, tail..] => {}
65 [None, Some(..), tail..] => {}
223e47cc
LB
66 [Some(_)] => {}
67 [None] => {}
68 [] => {}
69 }
70}