-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
changes to closure capture in Rust 2021 affect drop order of ignored arguments #199
Comments
I found this while running the 2021 edition migration over the Fuchsia codebase, you can see the full example pre-minimization in https://fuchsia-review.googlesource.com/c/fuchsia/+/684586/1/src/settings/service/src/tests/setting_handler_tests.rs if that's interesting. |
I've published a fix in async-trait 0.1.55. |
#203 seems to fix it for It drops the argument early if edition is set to 2021, and produces the migration lint. Although that example is quite contrived and doesn't affect me personally. |
The initial fix in 0.1.55 also broke a pattern that used to work: #[async_trait]
trait Generic<T> {
fn takes_ref(&self, thing: &T);
}
// no need for T: Send + Sync bound on this impl because &T is not used
#[async_trait]
impl<T> Generic<T> for () {
fn takes_ref(&self, _: &T) {}
} |
Playground demo
This code:
triggers the 2021 edition migration tooling to insert a
let _ = &__arg0;
line, in order to try to avoid the edition change changing drop ordering. If you don't do that, and change the edition, it really does change drop ordering:in edition 2018:
in edition 2021:
but regular async functions don't work that way, even in edition 2021 playground:
prints:
I think we do want the argument to be captured here, to match the behavior of async functions. That would also incidentally stop rustfix from making the odd suggestion. Surprisingly, the suggestion rustfix makes does actually work, which also seems like a bug to me -- I would have expected the
__arg0
arguments to have some kind of hygiene which prevented them from being named.The text was updated successfully, but these errors were encountered: