forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for helpful errors when copying into closures (rust-l…
- Loading branch information
1 parent
eec96e8
commit c99b2cb
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
fn closure1(+x: ~str) -> (~str, fn@() -> ~str) { | ||
let f = fn@() -> ~str { | ||
copy x | ||
//~^ WARNING implicitly copying a non-implicitly-copyable value | ||
//~^^ NOTE to copy values into a @fn closure, use a capture clause | ||
}; | ||
(x,f) | ||
} | ||
|
||
fn closure2(+x: util::NonCopyable) -> (util::NonCopyable, | ||
fn@() -> util::NonCopyable) { | ||
let f = fn@() -> util::NonCopyable { | ||
copy x | ||
//~^ ERROR copying a noncopyable value | ||
//~^^ NOTE non-copyable value cannot be copied into a @fn closure | ||
//~^^^ ERROR copying a noncopyable value | ||
}; | ||
(x,f) | ||
} | ||
fn closure3(+x: util::NonCopyable) { | ||
do task::spawn { | ||
let s = copy x; | ||
//~^ ERROR copying a noncopyable value | ||
//~^^ NOTE non-copyable value cannot be copied into a ~fn closure | ||
//~^^^ ERROR copying a noncopyable value | ||
error!("%?", s); | ||
} | ||
error!("%?", x); | ||
} | ||
fn main() { | ||
let x = ~"hello"; | ||
do task::spawn { | ||
let s = copy x; | ||
//~^ WARNING implicitly copying a non-implicitly-copyable value | ||
//~^^ NOTE to copy values into a ~fn closure, use a capture clause | ||
error!("%s from child", s); | ||
} | ||
error!("%s", x); | ||
} |