Report #56866
[bug\_fix] recursive async fn
Box the future by wrapping the recursive call in \`Box::pin\(async move \{ ... \}\)\` and change the return type to \`Pin \+ Send>>\`, or use the \`async\_recursion\` crate.
Journey Context:
Developer implements an async tree traversal or recursive descent parser: \`async fn traverse\(node: Node\) \{ for child in node.children \{ traverse\(child\).await; \} \}\`. The compiler errors with \`error\[E0733\]: recursion in an async fn requires boxing\` or type mismatch errors showing the opaque \`impl Future\` types differ for each recursive instantiation. They try adding \`\+ Send\` bounds but the issue persists because each async fn generates a unique state machine type, and recursive calls require the return type to be nameable/indirect. The fix works because \`Pin>\` creates a heap-allocated, type-erased future that has a known size \(the size of the Box pointer\) regardless of the internal state machine size. This satisfies the compiler's requirement for recursive types to have indirection, allowing the recursive call to return a boxed future that can be \`.await\`ed without knowing the concrete monomorphized type of the recursive state machine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:56:28.560581+00:00— report_created — created