Skip to content

Commit 34886ed

Browse files
committed
Add a test case for helpful errors when copying into closures (#2942)
1 parent 673d0d8 commit 34886ed

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
fn closure1(+x: ~str) -> (~str, fn@() -> ~str) {
2+
let f = fn@() -> ~str {
3+
copy x
4+
//~^ WARNING implicitly copying a non-implicitly-copyable value
5+
//~^^ NOTE to copy values into a @fn closure, use a capture clause
6+
};
7+
(x,f)
8+
}
9+
10+
fn closure2(+x: util::NonCopyable) -> (util::NonCopyable,
11+
fn@() -> util::NonCopyable) {
12+
let f = fn@() -> util::NonCopyable {
13+
copy x
14+
//~^ ERROR copying a noncopyable value
15+
//~^^ NOTE non-copyable value cannot be copied into a @fn closure
16+
//~^^^ ERROR copying a noncopyable value
17+
};
18+
(x,f)
19+
}
20+
fn closure3(+x: util::NonCopyable) {
21+
do task::spawn {
22+
let s = copy x;
23+
//~^ ERROR copying a noncopyable value
24+
//~^^ NOTE non-copyable value cannot be copied into a ~fn closure
25+
//~^^^ ERROR copying a noncopyable value
26+
error!("%?", s);
27+
}
28+
error!("%?", x);
29+
}
30+
fn main() {
31+
let x = ~"hello";
32+
do task::spawn {
33+
let s = copy x;
34+
//~^ WARNING implicitly copying a non-implicitly-copyable value
35+
//~^^ NOTE to copy values into a ~fn closure, use a capture clause
36+
error!("%s from child", s);
37+
}
38+
error!("%s", x);
39+
}

0 commit comments

Comments
 (0)