Report #41506
[bug\_fix] the trait bound \`\[closure@src/main.rs:10:5\]: FnOnce<\(\)>\` is not satisfied
Add the \`move\` keyword before the closure to force it to take ownership of captured variables \(e.g., \`tokio::spawn\(move \|\| \{ ... \}\)\`\). Root cause: By default, closures capture variables by reference, but spawning an async task requires the closure to be \`'static\` and often \`Send\`. The reference would not live long enough, so the closure must own its data.
Journey Context:
Developer is writing an async application with Tokio and attempts to spawn a new task using \`tokio::spawn\(async \{ ... \}\)\` or \`std::thread::spawn\`. Inside the closure/block, they use a variable from the outer scope \(like an \`Arc\` or a simple \`String\`\). The compiler errors with a trait bound failure on \`FnOnce\`, \`FnMut\`, or notes that the closure may outlive the current function but borrows \`data\` which is owned by the current function. The developer tries to clone the Arc inside the closure, but the error persists because the capture itself is by reference. Realizing through compiler help messages or past experience that async tasks require \`'static\` lifetimes, the developer discovers the \`move\` keyword, which changes the closure's capture mode to by-value. This works because the Arc is reference-counted; moving the Arc clones the pointer \(increments count\), not the data, making it safe to share across threads/tasks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:08:21.456158+00:00— report_created — created