-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Explain why borrows can't be held across yield point in async blocks/functions #78938
Comments
cc @estebank |
Hmm, reading that link, it looks like this issue is specific to multi-threaded executors and this would be fine without a |
This isn't specific to async, it also happens with |
What about something like
We could substitute "closures" in the non-async case as well, if it'd be helpful. |
Happy to help anyone who wants to implement this. |
Hi, I want to start contributing to Rust. Would this be a good first issue? |
@rustbot claim |
@1000teslas that'd be great! See https://rustc-dev-guide.rust-lang.org/ for instructions on getting started, and for your change I'd start by finding where the current error is emitted (it will be somewhere in |
I think the current error message is emitted from |
@1000teslas yes, those are right (or at least close enough that you can fix any issues during review). |
I have tried implementing the error message for async block here. I am not sure what errors an async function would have. For example, I tried messing around here with borrowing past an await point in an async function, but it seems to compile. I am not sure how to keep lines under 100 characters when mentioning urls in an error message. Also, for some reason, |
Explain why borrows can't be held across yield point in async blocks For rust-lang#78938.
Explain why borrows can't be held across yield point in async blocks For rust-lang#78938.
Explain why borrows can't be held across yield point in async blocks For rust-lang#78938.
Should this issue be closed? |
Consider the following code:
The error message has a helpful hint:
But it doesn't explain very well why
move
is necessary:In particular, 'async block may outlive the current function' makes no sense without a very good mental model of async: the future is
await
ed within the current function, so of course it can't outlive it. The thing to realize here is that even though it's written as one function, it's actually two: one executed before the yield point, and one after, and the stack space for the first function goes away when you callawait
.It would be nice to instead say something like
The text was updated successfully, but these errors were encountered: