rust/src/test/ui/pattern/slice-pattern-const.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2018-11-29 11:58:25 +00:00
//compile-pass
fn main() {
2018-11-26 08:56:39 +00:00
let s = &[0x00; 4][..]; //Slice of any value
const MAGIC_TEST: &[u8] = b"TEST"; //Const slice to pattern match with
match s {
MAGIC_TEST => (),
[0x00, 0x00, 0x00, 0x00] => (),
2018-11-29 11:58:25 +00:00
[84, 69, 83, 84] => (), // this should warn
_ => (),
}
match s {
[0x00, 0x00, 0x00, 0x00] => (),
MAGIC_TEST => (),
[84, 69, 83, 84] => (), // this should warn
_ => (),
}
match s {
[0x00, 0x00, 0x00, 0x00] => (),
[84, 69, 83, 84] => (),
MAGIC_TEST => (), // this should warn
2018-11-26 08:56:39 +00:00
_ => (),
}
2018-12-07 18:06:22 +00:00
const FOO: [u8; 1] = [4];
match [99] {
[0x00] => (),
[4] => (),
FOO => (), // this should warn
_ => (),
}
const BAR: &[u8; 1] = &[4];
match &[99] {
[0x00] => (),
[4] => (),
BAR => (), // this should warn
b"a" => (),
_ => (),
}
const BOO: &[u8; 0] = &[];
match &[] {
[] => (),
BOO => (), // this should warn
b"" => (),
_ => (),
}
}