Fix redundant closure call async false positive#17107
Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Reminder, once the PR becomes ready for a review, use |
|
Thanks for the review!
Yeah happy to remove it. I added it because its one of the possible "capture clauses" in the ast. I don't know what the policy is on supporting unstable features. The following code compiles on nightly: #![allow(unused)]
#![feature(ergonomic_clones)]
fn maybe() -> Option<()> {
Some(())
}
async fn test() {
let async_result = (async use || {
if maybe().is_none() {
Some(0)
} else {
Some(42)
}
})()
.await;
}
fn main() {}But obviously the feature may never be stabilised so you could argue its dead code. Up to you. |
|
@rustbot ready |
It can be used right now even when unstable, so I'd prefer we keep it and add tests. If this is removed from the compiler, Clippy won't compile anymore unless the relevant code is removed as well, so we won't accumulate technical debt there. |
5020155 to
ef50c1d
Compare
|
Ok, done! I elected for @rustbot ready |
On the contrary, I would prefer that we are forced to change it when the feature becomes complete to not keep a useless |
Previously, async closures containing early returns which were
immediately called triggered the `redundant_closure_call` lint.
Regular non-async closures with these early return statements did not
trigger these lints.
Async closures of both kinds (`async || {}` and `|| async {}`) trigger
some desugaring which needs to be appropriately handled when looking for
early return statements. This commit implements that logic.
Also remove some redundant allows and make expects more granular instead of applying to the whole module.
Previously, async closures containing early returns which were immediately called triggered the
redundant_closure_calllint. Regular non-async closures with these early return statements did not trigger these lints.Async closures of both kinds (
async || {}and|| async {}) trigger some desugaring which needs to be appropriately handled when looking for early return statements. This commit implements that logic.fixes: #16232
changelog: [
redundant_closure_call]: Fix false positive on async closures with early returns