Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing 'implicit copy' warnings when copying into heap closures without a capture clause #2942

Closed
bblum opened this issue Jul 17, 2012 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@bblum
Copy link
Contributor

bblum commented Jul 17, 2012

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?

@nikomatsakis
Copy link
Contributor

this shouldn't be hard to do, the code in question is in kind.rs. Right now it all calls things like check_copy() with no indication of why the value must be copyable.

@catamorphism
Copy link
Contributor

I'm going to remove the RFC tag since making an error message more helpful is something we should always do where possible; it doesn't require consensus :-)

@ghost ghost assigned bblum Aug 24, 2012
@bblum bblum closed this as completed in 673d0d8 Aug 24, 2012
@bblum bblum removed their assignment Jun 16, 2014
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 29, 2023
Make `--quiet` actually do something

address review from rust-lang/miri#2941 (comment)
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Automatically create pull requests from the result of running `cargo
update` every Monday morning. This should avoid the need for manual PRs
to update Cargo.lock, which seemingly dependabot wouldn't take care of.
We now only use dependabot to update github actions.

This revives what I had initially proposed in rust-lang#2895 in light of rust-lang#2940.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

3 participants