-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Inconsistent move behavior in closure with async block #81653
Comments
Just |
Here's an example of where
This is almost the exact problem that I ran into the other day. I would expect this to compile - Adding |
The difference between |
Also ran into this just today - pretty frustrating to run into because there's not reason not to just... copy the copy type, right? I found this issue while I was about to make a new one. I have a slightly more elaborate example that boils down to largely the same thing as vultix's example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5bd544f234579b29974d1e62f6fe75ec The workarounds are pretty painful here for something you'd expect to not be an issue |
I think the issue here is that this isn't an async closure, but a closure with an async block. |
This sounds like the sort of thing that might have a fairly small fix and be a good starter issue. Maybe someone wants to write up some mentoring instructions for it? @rustbot label E-needs-mentor |
This closure fails to compile:
I'd expect that this would compile -
val
should be moved into the async closure.This is inconsistent with the following cases where it compiles (playground link):
val
to a!Copy
type (such asString
)async
keywordThis has a serious drawback in that it forces you to use
async move
even when you can't move everything into the async block.Workaround
This is super unergonomic, but as a workaround you can surround the copy type with a
NonCopy
newtype.Meta
This happens on Stable, Nightly, and Beta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: