Closed
Description
One of my teammates during ICFP (#2928) who didn't already know Rust was boggled by a particularly insistent warning.
a.rs:5:17: 5:18 warning: implicitly copying a non-implicitly-copyable value
a.rs:5 bar(copy v, i)
^
Rustc was really complaining that v was being copied into a heap closure. The code looked like this:
fn bar(+v: ~[int], i: uint) -> int { v[i] }
fn foo(v: ~[int]) -> fn@(uint) -> int {
ret |i| {
bar(copy v, i)
}
}
fn main() { #error["%d", foo(~[5])(0)]; }
The solution was to write copy v
in the capture clause.
Perhaps the warning message could be more informative? Could it hint that the copy comes from building the heap closure, and suggest writing a capture clause?