Closed ComputerDruid closed 1 year ago
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.
https://github.com/dtolnay/async-trait/pull/203 seems to fix it for _
patterns as arguments, but not patterns with underscores nested inside them:
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) {}
}
I believe the remaining edition-sensitive cases have been resolved in #232 and #234.
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.