-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone
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?
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.