Skip to content

Commit 6c83fe4

Browse files
Jakub Wieczorekgraydon
Jakub Wieczorek
authored andcommitted
Add more tests
1 parent 6530fd3 commit 6c83fe4

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn a() -> &int {
2+
let vec = [1, 2, 3, 4];
3+
let tail = match vec {
4+
[a, ..tail] => &tail[0], //~ ERROR illegal borrow
5+
_ => fail ~"foo"
6+
};
7+
move tail
8+
}
9+
10+
fn main() {
11+
let fifth = a();
12+
io::println(fmt!("%d", *fifth));
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let a = [mut 1, 2, 3, 4];
3+
let _ = match a {
4+
[1, 2, ..move tail] => tail,
5+
_ => core::util::unreachable()
6+
};
7+
a[0] = 0; //~ ERROR: use of moved variable
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
fn main() {
2+
let x = @[1, 2, 3];
3+
match x {
4+
[2, .._] => core::util::unreachable(),
5+
[1, ..tail] => {
6+
assert tail == [2, 3];
7+
}
8+
[_] => core::util::unreachable(),
9+
[] => core::util::unreachable()
10+
}
11+
12+
let y = (~[(1, true), (2, false)], 0.5);
13+
match y {
14+
([_, _, _], 0.5) => core::util::unreachable(),
15+
([(1, a), (b, false), ..tail], _) => {
16+
assert a == true;
17+
assert b == 2;
18+
assert tail.is_empty();
19+
}
20+
([..tail], _) => core::util::unreachable()
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
let x = &[1, 2, 3, 4, 5];
3+
if !x.is_empty() {
4+
let el = match x {
5+
[1, ..ref tail] => &tail[0],
6+
_ => core::util::unreachable()
7+
};
8+
io::println(fmt!("%d", *el));
9+
}
10+
}

0 commit comments

Comments
 (0)