Weirdness around async function with error "implementation of FnOnce is not general enough" #114177
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.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
This code is the result of minimizing a compiler error in an async function using
Itertools::unique
. Compiling this code is weird in several ways:1:
Compilation fails with this message:
This message is confusing. Why are there two lifetimes? What does the "actually implements" line mean? How can I fix it?
2:
The code compiles when removing the Send bound. This is confusing because the error message does not mention Send. Why does the lifetime error message cause the Future to not be Send? Why do the following changes to the code fix the lifetime error and make the Future Send?
3:
The code can be made to compile by moving the inline closure into a separate variable:
This is surprising. Why does inlining the definition of the closure cause the code to not compile?
4:
The code can be made to compile by not holding the iterator across the await point:
This is surprising because the error message does not indicate the lifetime of the iterator itself is a problem.
Why does it make a difference whether there is a
{}
block or a manual drop?The text was updated successfully, but these errors were encountered: