rust/tests/ui/pattern/bindings-after-at/slice-patterns.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
786 B
Rust
Raw Normal View History

// Test bindings-after-at with slice-patterns
// run-pass
#[derive(Debug, PartialEq)]
enum MatchArm {
Arm(usize),
Wild,
}
fn test(foo: &[i32]) -> MatchArm {
match foo {
[bar @ .., n] if n == &5 => {
for i in bar {
assert!(i < &5);
}
MatchArm::Arm(0)
},
bar @ [x0, .., xn] => {
assert_eq!(x0, &1);
assert_eq!(x0, &1);
assert_eq!(xn, &4);
assert_eq!(bar, &[1, 2, 3, 4]);
MatchArm::Arm(1)
},
_ => MatchArm::Wild,
}
}
fn main() {
let foo = vec![1, 2, 3, 4, 5];
assert_eq!(test(&foo), MatchArm::Arm(0));
assert_eq!(test(&foo[..4]), MatchArm::Arm(1));
assert_eq!(test(&foo[0..1]), MatchArm::Wild);
}