diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-23 22:20:34 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-23 22:20:34 -0400 |
| commit | 34886ed488f6cc18c3fdc20cdeccab6178e00c0f (patch) | |
| tree | 84d138d175714a14087b67685bf40533ce3e2eed | |
| parent | 673d0d83cf39c3a21e4e9a9b3911c0fac5e1971d (diff) | |
| download | rust-34886ed488f6cc18c3fdc20cdeccab6178e00c0f.tar.gz rust-34886ed488f6cc18c3fdc20cdeccab6178e00c0f.zip | |
Add a test case for helpful errors when copying into closures (#2942)
| -rw-r--r-- | src/test/compile-fail/copy-into-closure.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/compile-fail/copy-into-closure.rs b/src/test/compile-fail/copy-into-closure.rs new file mode 100644 index 00000000000..8ee2a4fd3ae --- /dev/null +++ b/src/test/compile-fail/copy-into-closure.rs @@ -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); +} |
