]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/usefulness/non-exhaustive-match.rs
Update llvm submodule
[rust.git] / src / test / ui / pattern / usefulness / non-exhaustive-match.rs
1 #![feature(slice_patterns)]
2 #![allow(illegal_floating_point_literal_pattern)]
3
4 enum T { A, B }
5
6 fn main() {
7     let x = T::A;
8     match x { T::B => { } } //~ ERROR non-exhaustive patterns: `A` not covered
9     match true { //~ ERROR non-exhaustive patterns: `false` not covered
10       true => {}
11     }
12     match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
13       None => {}
14     }
15     match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, std::i32::MIN..=3i32)`
16                       //  and `(_, _, 5i32..=std::i32::MAX)` not covered
17       (_, _, 4) => {}
18     }
19     match (T::A, T::A) { //~ ERROR non-exhaustive patterns: `(A, A)` not covered
20       (T::A, T::B) => {}
21       (T::B, T::A) => {}
22     }
23     match T::A { //~ ERROR non-exhaustive patterns: `B` not covered
24       T::A => {}
25     }
26     // This is exhaustive, though the algorithm got it wrong at one point
27     match (T::A, T::B) {
28       (T::A, _) => {}
29       (_, T::A) => {}
30       (T::B, T::B) => {}
31     }
32     let vec = vec![Some(42), None, Some(21)];
33     let vec: &[Option<isize>] = &vec;
34     match *vec { //~ ERROR non-exhaustive patterns: `[]` not covered
35         [Some(..), None, ref tail @ ..] => {}
36         [Some(..), Some(..), ref tail @ ..] => {}
37         [None] => {}
38     }
39     let vec = vec![1];
40     let vec: &[isize] = &vec;
41     match *vec {
42         [_, ref tail @ ..] => (),
43         [] => ()
44     }
45     let vec = vec![0.5f32];
46     let vec: &[f32] = &vec;
47     match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
48         [0.1, 0.2, 0.3] => (),
49         [0.1, 0.2] => (),
50         [0.1] => (),
51         [] => ()
52     }
53     let vec = vec![Some(42), None, Some(21)];
54     let vec: &[Option<isize>] = &vec;
55     match *vec {
56         [Some(..), None, ref tail @ ..] => {}
57         [Some(..), Some(..), ref tail @ ..] => {}
58         [None, None, ref tail @ ..] => {}
59         [None, Some(..), ref tail @ ..] => {}
60         [Some(_)] => {}
61         [None] => {}
62         [] => {}
63     }
64 }