]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/non-exhaustive-match.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / non-exhaustive-match.rs
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
11 enum t { a, b, }
12
13 fn main() {
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
17       true => {}
18     }
19     match Some(10i) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
20       None => {}
21     }
22     match (2i, 3i, 4i) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered
23       (_, _, 4) => {}
24     }
25     match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered
26       (t::a, t::b) => {}
27       (t::b, t::a) => {}
28     }
29     match t::a { //~ ERROR non-exhaustive patterns: `b` not covered
30       t::a => {}
31     }
32     // This is exhaustive, though the algorithm got it wrong at one point
33     match (t::a, t::b) {
34       (t::a, _) => {}
35       (_, t::a) => {}
36       (t::b, t::b) => {}
37     }
38     let vec = vec!(Some(42i), None, Some(21i));
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..] => {}
43         [None] => {}
44     }
45     let vec = vec!(1i);
46     let vec: &[isize] = vec.as_slice();
47     match vec {
48         [_, tail..] => (),
49         [] => ()
50     }
51     let vec = vec!(0.5f32);
52     let vec: &[f32] = vec.as_slice();
53     match vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
54         [0.1, 0.2, 0.3] => (),
55         [0.1, 0.2] => (),
56         [0.1] => (),
57         [] => ()
58     }
59     let vec = vec!(Some(42i), None, Some(21i));
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..] => {}
66         [Some(_)] => {}
67         [None] => {}
68         [] => {}
69     }
70 }