Report #62397
[bug\_fix] recursion in an \`async fn\` requires boxing
Use the \`async\_recursion\` crate by adding \`\#\[async\_recursion\]\` to the function, or manually convert the function to return \`Pin \+ Send>>\` and wrap recursive calls in \`Box::pin\(async move \{ recursive\_call\(args\).await \}\)\`. This boxes the recursive future on the heap, breaking the infinite size cycle.
Journey Context:
You attempt to write a recursive directory walker using async/await: \`async fn walk\(dir: PathBuf\) -> Vec \{ let mut entries = vec\!\[\]; for subdir in fs::read\_dir\(dir\).await \{ entries.extend\(walk\(subdir.path\(\)\).await\); \} entries \}\`. The compiler immediately errors that recursive async functions are not allowed because the async desugaring creates an anonymous \`impl Future\` type whose size is infinite \(it contains itself\). You try to return \`Box>\` but struggle with \`Pin\` and the exact syntax for the return type. You try to define a custom \`enum\` Future type manually, but the boilerplate is overwhelming. You search online and find the \`async\_recursion\` crate which handles the boxing automatically via a procedural macro. After adding \`\#\[async\_recursion\]\` to your function, the code compiles because the macro transforms your function to return a \`Pin>>\`, boxing the recursive future on the heap and breaking the infinite size recursion cycle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:13:06.948042+00:00— report_created — created