Recursive async functions don't internally implement auto traits #123072
Labels
A-async-await
Area: Async & Await
A-auto-traits
Area: auto traits (e.g., `auto trait Send {}`)
A-trait-system
Area: Trait system
AsyncAwait-Triaged
Async-await issues that have been triaged during a working group meeting.
C-bug
Category: This is a bug.
fixed-by-next-solver
Fixed by the next-generation trait solver, `-Znext-solver`.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-async
Working group: Async & await
I tried this code:
I expected to see this happen: Compiles successfully.
Instead, this happened:
It seems like recursive async functions only externally implement auto traits like
Send
. If you requireSend
inside its own body, then the function does not compile. This is extra unfortunate because recursive async functions require indirection, and one way of achieving that is by spawning it on a multithreaded executor. The diagnostic is also unhelpful. I'm not sure what it's actually for, but it sounds impossible to apply to this situation. The real solution I found is to manually desugar the async function into a regular function that returns animpl Future + Send
:However, it would be ideal if the original was allowed as-is.
This is similar to #119727 but without the cycle error.
This was originally found in URLO: With tokio, “future returned by ‘a’ is not ‘Send’”, with tiny example
Meta
rustc 1.79.0-nightly 2024-03-24 from play.rust-lang.org
The text was updated successfully, but these errors were encountered: