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