Infer async closure args from Fn bound even if there is no corresponding Future bound on return by compiler-errors · Pull Request #129072 · rust-lang/rust (original) (raw)

In #127482, I implemented the functionality to infer an async closure signature when passed into a function that has Fn + Future where clauses that look like:

fn whatever(callback: F)
where
  F: Fn(Arg) -> Fut,
  Fut: Future<Output = Out>,

However, #127781 demonstrates that this is still incomplete to address the cases users care about. So let's not bail when we fail to find a Future bound, and try our best to just use the args from the Fn bound if we find it. This is fine since most users of closures only really care about the argument types for inference guidance, since we require the receiver of a . method call to be known in order to probe methods.

When I experimented with programmatically rewriting || async {} to async || {} in #127827, this also seems to have fixed ~5000 regressions (probably all coming from usages TryFuture/TryStream from futures-rs): the before and after crater runs.

Fixes #127781.