]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/non-exhaustive-match.rs
test: Make manual changes to deal with the fallout from removal of
[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 = a;
15     match x { b => { } } //~ ERROR non-exhaustive patterns
16     match true { //~ ERROR non-exhaustive patterns
17       true => {}
18     }
19     match Some(10) { //~ ERROR non-exhaustive patterns
20       None => {}
21     }
22     match (2, 3, 4) { //~ ERROR non-exhaustive patterns
23       (_, _, 4) => {}
24     }
25     match (a, a) { //~ ERROR non-exhaustive patterns
26       (a, b) => {}
27       (b, a) => {}
28     }
29     match a { //~ ERROR b not covered
30       a => {}
31     }
32     // This is exhaustive, though the algorithm got it wrong at one point
33     match (a, b) {
34       (a, _) => {}
35       (_, a) => {}
36       (b, b) => {}
37     }
38     let vec = vec!(Some(42), None, Some(21));
39     let vec: &[Option<int>] = vec.as_slice();
40     match vec {
41         //~^ ERROR non-exhaustive patterns: vectors of length 0 not covered
42         [Some(..), None, ..tail] => {}
43         [Some(..), Some(..), ..tail] => {}
44         [None] => {}
45     }
46     let vec = vec!(1);
47     let vec: &[int] = vec.as_slice();
48     match vec {
49         [_, ..tail] => (),
50         [] => ()
51     }
52     let vec = vec!(0.5);
53     let vec: &[f32] = vec.as_slice();
54     match vec { //~ ERROR non-exhaustive patterns: vectors of length 4 not covered
55         [0.1, 0.2, 0.3] => (),
56         [0.1, 0.2] => (),
57         [0.1] => (),
58         [] => ()
59     }
60     let vec = vec!(Some(42), None, Some(21));
61     let vec: &[Option<int>] = vec.as_slice();
62     match vec {
63         [Some(..), None, ..tail] => {}
64         [Some(..), Some(..), ..tail] => {}
65         [None, None, ..tail] => {}
66         [None, Some(..), ..tail] => {}
67         [Some(_)] => {}
68         [None] => {}
69         [] => {}
70     }
71 }