You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 here18 | 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".
The text was updated successfully, but these errors were encountered:
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:
Then, when you call
debug_dump_dict()
more than once, you'll get an error message like this: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
".The text was updated successfully, but these errors were encountered: