]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/issue-46920-byte-array-patterns.rs
Auto merge of #106349 - LeSeulArtichaut:dyn-star-tracking-issue, r=jackh726
[rust.git] / src / test / ui / match / issue-46920-byte-array-patterns.rs
1 // run-pass
2 const CURSOR_PARTITION_LABEL: &'static [u8] = b"partition";
3 const CURSOR_EVENT_TYPE_LABEL: &'static [u8] = b"event_type";
4 const BYTE_PATTERN: &'static [u8; 5] = b"hello";
5
6 fn match_slice(x: &[u8]) -> u32 {
7     match x {
8         CURSOR_PARTITION_LABEL => 0,
9         CURSOR_EVENT_TYPE_LABEL => 1,
10         _ => 2,
11     }
12 }
13
14 fn match_array(x: &[u8; 5]) -> bool {
15     match x {
16         BYTE_PATTERN => true,
17         _ => false
18     }
19 }
20
21 fn main() {
22     assert_eq!(match_slice(b"abcde"), 2);
23     assert_eq!(match_slice(b"event_type"), 1);
24     assert_eq!(match_slice(b"partition"), 0);
25
26     assert_eq!(match_array(b"hello"), true);
27     assert_eq!(match_array(b"hella"), false);
28 }