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