Closure in async block fails to compile when it should, issues incorrect/misleading diagnostic #96128
Labels
A-async-await
Area: Async & Await
AsyncAwait-Triaged
Async-await issues that have been triaged during a working group meeting.
C-bug
Category: This is a bug.
I've put the code reproducing this issue in the cdhowie/warp-lifetime-issue-repro repository as it has a dependency on warp. I have not been able to build a reproduction of this issue outside of warp or rocket-rs, but I believe the issue is with the compiler nonetheless, for a few reasons. I have been able to reproduce the issue on all of the following Rust Docker images:
The summary is that passing a very simple non-capturing closure in an async route handler causes a lifetime mismatch error, referencing a type that is not used or demanded in the handler:
Nowhere in the handler is an
FnOnce
built, nor is one asked for byIterator::filter()
so at the very least the diagnostic is misleading. However, rewriting the code to use a free function instead of a closure allows the code to compile:I can't see any reason why a closure should fail here but a free function should work; I'd expect them to be effectively identical since the closure doesn't capture anything from its environment.
For more specific details, see the repository linked above. (I'm happy to copy the repro code directly into this issue if desired, just let me know.)
The text was updated successfully, but these errors were encountered: