Skip to content

Consider adding a help message when the moved value was a FnOnce #40855

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

Closed
jorendorff opened this issue Mar 27, 2017 · 0 comments
Closed

Consider adding a help message when the moved value was a FnOnce #40855

jorendorff opened this issue Mar 27, 2017 · 0 comments

Comments

@jorendorff
Copy link
Contributor

jorendorff commented Mar 27, 2017

In Programming Rust, a book I'm writing, there's this:


It doesn't happen often, but once in a great while you'll write some closure code that unintentionally uses up a value:

let dict = produce_glossary();
let debug_dump_dict = || {
    for (key, value) in dict {  // oops!
        println!("{:?} - {:?}", key, value);
    }
};

Then, when you call debug_dump_dict() more than once, you'll get an error message like this:

error[E0382]: use of moved value: `debug_dump_dict`
  --> debug_dump_dict.rs:18:5
   |
17 |     debug_dump_dict();
   |     --------------- value moved here
18 |     debug_dump_dict();
   |     ^^^^^^^^^^^^^^^ value used here after move
   |

This isn't a very helpful error message, unless you know what Rust is trying to tell you: a previous call to this closure moved it, because this closure is a FnOnce.


In reviewing the book, @brson encouraged me to file a bug about the diagnostic here. It's probably not worth doing anything, since closures aren't normally used this way. (I considered removing the passage from the book rather than file this bug.)

But what the heck. Conceivably a "help" could be added here that says "closure was moved because it only implements FnOnce".

bors added a commit that referenced this issue May 19, 2017
Add help message if a FnOnce is moved

Fixes #40855.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant