]> git.proxmox.com Git - rustc.git/blame - src/test/ui/pattern/usefulness/slice-pattern-const.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / pattern / usefulness / slice-pattern-const.rs
CommitLineData
0731742a
XL
1#![deny(unreachable_patterns)]
2
3fn main() {
4 let s = &[0x00; 4][..]; //Slice of any value
5 const MAGIC_TEST: &[u8] = b"TEST"; //Const slice to pattern match with
6 match s {
7 MAGIC_TEST => (),
8 [0x00, 0x00, 0x00, 0x00] => (),
9 [84, 69, 83, 84] => (), //~ ERROR unreachable pattern
10 _ => (),
11 }
12 match s {
13 [0x00, 0x00, 0x00, 0x00] => (),
14 MAGIC_TEST => (),
15 [84, 69, 83, 84] => (), //~ ERROR unreachable pattern
16 _ => (),
17 }
18 match s {
19 [0x00, 0x00, 0x00, 0x00] => (),
20 [84, 69, 83, 84] => (),
21 MAGIC_TEST => (), //~ ERROR unreachable pattern
22 _ => (),
23 }
24 const FOO: [u8; 1] = [4];
25 match [99] {
26 [0x00] => (),
27 [4] => (),
28 FOO => (), //~ ERROR unreachable pattern
29 _ => (),
30 }
31 const BAR: &[u8; 1] = &[4];
32 match &[99] {
33 [0x00] => (),
34 [4] => (),
35 BAR => (), //~ ERROR unreachable pattern
36 b"a" => (),
37 _ => (),
38 }
39
40 const BOO: &[u8; 0] = &[];
41 match &[] {
42 [] => (),
43 BOO => (), //~ ERROR unreachable pattern
44 b"" => (), //~ ERROR unreachable pattern
45 _ => (), //~ ERROR unreachable pattern
46 }
60c5eb7d
XL
47
48 const CONST1: &[bool; 1] = &[true];
49 match &[false] {
50 CONST1 => {}
51 [true] => {} //~ ERROR unreachable pattern
52 [false] => {}
53 }
0731742a 54}