]> git.proxmox.com Git - rustc.git/blame - src/test/ui/pattern/usefulness/non-exhaustive-match.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / test / ui / pattern / usefulness / non-exhaustive-match.rs
CommitLineData
7cac9316 1#![allow(illegal_floating_point_literal_pattern)]
c34b1796 2
0731742a 3enum T { A, B }
223e47cc
LB
4
5fn main() {
0731742a
XL
6 let x = T::A;
7 match x { T::B => { } } //~ ERROR non-exhaustive patterns: `A` not covered
1a4d82fc 8 match true { //~ ERROR non-exhaustive patterns: `false` not covered
223e47cc
LB
9 true => {}
10 }
85aaf69f 11 match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
1a4d82fc 12 None => {}
223e47cc 13 }
f035d41b
XL
14 match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, i32::MIN..=3_i32)`
15 // and `(_, _, 5_i32..=i32::MAX)` not covered
223e47cc
LB
16 (_, _, 4) => {}
17 }
fc512014 18 match (T::A, T::A) { //~ ERROR non-exhaustive patterns: `(A, A)` and `(B, B)` not covered
0731742a
XL
19 (T::A, T::B) => {}
20 (T::B, T::A) => {}
223e47cc 21 }
0731742a
XL
22 match T::A { //~ ERROR non-exhaustive patterns: `B` not covered
23 T::A => {}
223e47cc
LB
24 }
25 // This is exhaustive, though the algorithm got it wrong at one point
0731742a
XL
26 match (T::A, T::B) {
27 (T::A, _) => {}
28 (_, T::A) => {}
29 (T::B, T::B) => {}
1a4d82fc 30 }
c30ab7b3 31 let vec = vec![Some(42), None, Some(21)];
85aaf69f 32 let vec: &[Option<isize>] = &vec;
3157f602 33 match *vec { //~ ERROR non-exhaustive patterns: `[]` not covered
416331ca
XL
34 [Some(..), None, ref tail @ ..] => {}
35 [Some(..), Some(..), ref tail @ ..] => {}
223e47cc
LB
36 [None] => {}
37 }
c30ab7b3 38 let vec = vec![1];
85aaf69f 39 let vec: &[isize] = &vec;
3157f602 40 match *vec {
416331ca 41 [_, ref tail @ ..] => (),
223e47cc
LB
42 [] => ()
43 }
c30ab7b3 44 let vec = vec![0.5f32];
85aaf69f 45 let vec: &[f32] = &vec;
60c5eb7d 46 match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _, ..]` not covered
223e47cc
LB
47 [0.1, 0.2, 0.3] => (),
48 [0.1, 0.2] => (),
49 [0.1] => (),
50 [] => ()
51 }
c30ab7b3 52 let vec = vec![Some(42), None, Some(21)];
85aaf69f 53 let vec: &[Option<isize>] = &vec;
3157f602 54 match *vec {
416331ca
XL
55 [Some(..), None, ref tail @ ..] => {}
56 [Some(..), Some(..), ref tail @ ..] => {}
57 [None, None, ref tail @ ..] => {}
58 [None, Some(..), ref tail @ ..] => {}
223e47cc
LB
59 [Some(_)] => {}
60 [None] => {}
61 [] => {}
62 }
63}