Report #12897
[bug\_fix] recursion in an \`async fn\` requires boxing \[E0733\]
Box the recursive future using \`Box::pin\(\)\` and annotate the function with the \`async\_recursion\` crate macro, or manually rewrite the recursion as a loop or an enum-based state machine that returns \`Pin>\`.
Journey Context:
The developer writes an async function that calls itself recursively, such as \`async fn traverse\(node: Node\) \{ for child in node.children \{ traverse\(child\).await; \} \}\`. The compiler errors with E0733 because an async fn returns an anonymous Future type whose size must be known at compile time; recursive calls would create an infinitely large type \(the future containing the future containing...\). The developer first tries to wrap the recursive call in \`Box::pin\`, but struggles with the \`Pin\` API and the fact that the function signature itself must change to return \`Pin \+ Send>>\`. They discover the \`async-recursion\` crate which handles the boxing automatically via a procedural macro. Applying \`\#\[async\_recursion\]\` to the function fixes it because it transforms the function to return a boxed future, introducing the necessary indirection that makes the recursive type finite \(a pointer to the next future, not the future itself\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:16:04.317660+00:00— report_created — created