Skip to content

Commit 070137c

Browse files
committed
Add one more test for vector destructuring
1 parent 9e85589 commit 070137c

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/test/run-pass/vec-matching.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn main() {
1+
fn a() {
22
let x = [1];
33
match x {
44
[_, _, _, _, _, .._] => ::core::util::unreachable(),
@@ -11,3 +11,44 @@ pub fn main() {
1111
[] => ::core::util::unreachable()
1212
}
1313
}
14+
15+
fn b() {
16+
let x = [1, 2, 3];
17+
match x {
18+
[a, b, ..c] => {
19+
fail_unless!(a == 1);
20+
fail_unless!(b == 2);
21+
fail_unless!(c == &[3]);
22+
}
23+
_ => fail!()
24+
}
25+
match x {
26+
[..a, b, c] => {
27+
fail_unless!(a == &[1]);
28+
fail_unless!(b == 2);
29+
fail_unless!(c == 3);
30+
}
31+
_ => fail!()
32+
}
33+
match x {
34+
[a, ..b, c] => {
35+
fail_unless!(a == 1);
36+
fail_unless!(b == &[2]);
37+
fail_unless!(c == 3);
38+
}
39+
_ => fail!()
40+
}
41+
match x {
42+
[a, b, c] => {
43+
fail_unless!(a == 1);
44+
fail_unless!(b == 2);
45+
fail_unless!(c == 3);
46+
}
47+
_ => fail!()
48+
}
49+
}
50+
51+
pub fn main() {
52+
a();
53+
b();
54+
}

0 commit comments

Comments
 (0)