Skip to content

Commit 4837a57

Browse files
committed
Add tests for destructuring locals
1 parent 92240eb commit 4837a57

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:refutable pattern
2+
3+
tag xx {
4+
xx(int);
5+
yy;
6+
}
7+
8+
fn main() {
9+
let @{x:xx(x), y} = @{x: xx(10), y: 20};
10+
assert x + y == 30;
11+
}

src/test/run-pass/for-destruct.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
for {x, y}: {x: int, y: int} in ~[{x: 10, y: 20}, {x: 30, y: 0}] {
3+
assert x + y == 30;
4+
}
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
iter x() -> {x: int, y: int} {
2+
let i = 0;
3+
while i < 40 {
4+
put {x: i, y: 30 - i};
5+
i += 10;
6+
}
7+
}
8+
9+
fn main() {
10+
for each {x, y}: {x: int, y: int} in x() {
11+
assert x + y == 30;
12+
}
13+
}

src/test/run-pass/let-destruct.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tag xx {
2+
xx(int);
3+
}
4+
5+
fn main() {
6+
let @{x:xx(x), y} = @{x: xx(10), y: 20};
7+
assert x + y == 30;
8+
}

0 commit comments

Comments
 (0)