-
Notifications
You must be signed in to change notification settings - Fork 12.5k
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Error message for closure with async block needs improvement #68119
Comments
It took me a while to process what's going on here. I guess the biggest problem is the "move of In contrast, we don't show (for closures) the "closure creation" as the point of a move (although it technically is). We just show the point within the closure body that's responsible. Looking more closely at the example, it seems like there are actually several moves happening
and so I guess we are suppressing one but not the rest. I'd have to go digging a bit to give more specifics on how to fix. |
@rustbot modify labels to +AsyncAwait-OnDeck Good diagnostics are a priority |
I also got bitten by this error message
And the error got me confused because I'm not familiar with the "generator" concept - I have seen it in some blog posts but never met it in practice.
Consider a very similar situation
which yields
I've much more accustomed to thinking about closures - these I imagine as structures that capture the context in their fields. So this leads me to a solution much faster. However, note that E0507 talks about a borrowed value, but here it is hard to see where it is borrowed since everything is marked as
These are just my thoughts on a topic, hope that might help you! Thanks a lot for your tremendous works! |
I seem to get bitten by this every time I'm working with arr.into_iter().map(move |_e| {
async move {
let value = cloned_value.clone();
println!("{:?}", value.lock().ok())
}
}) to arr.into_iter().map(move |_e| {
let value = cloned_value.clone();
async move {
println!("{:?}", value.lock().ok())
}
}) i.e. moving the
|
Playground
gives
Note
move occurs due to use in generator
. Also, the code is being output twice, for some reason.If you take this out of the async context by removing
async
and uncommentingready(())
, you get a better suggestion to useas_ref()
and an all-around cleaner error message:Thanks to @JakeEhrlich for originally reporting this.
The text was updated successfully, but these errors were encountered: