Report #94035
[bug\_fix] recursion in an \`async fn\` requires boxing or \`async\_recursion\` crate
Use the \`async\_recursion\` crate by adding \`\#\[async\_recursion\]\` attribute to the function, or manually box the future: change return type to \`BoxFuture<'static, ReturnType>\` and wrap the recursive call body in \`Box::pin\(async move \{ ... \}\)\`.
Journey Context:
Developer implements a recursive algorithm like tree traversal or directory crawling using \`async fn visit\(node: Node\)\`. They call \`visit\(child\).await\` inside the function. The compiler errors with \`error\[E0733\]: recursion in an async fn requires boxing\` or a type mismatch where the recursive call returns an opaque type that doesn't match the parent function's future type. The developer learns that \`async fn\` desugars to a unique anonymous \`Future\` type; recursion would require the type to contain itself, creating an infinitely sized type. They find the \`async\_recursion\` crate which rewrites the function to use dynamic dispatch \(\`BoxFuture\`\), or they manually implement \`Future\` or use \`Box::pin\` to allocate the recursive future on the heap, breaking the infinite size cycle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:25:33.865552+00:00— report_created — created