Report #68197
[bug\_fix] trait bound \`dyn MyTrait: Send\` is not satisfied when spawning async tasks or sending trait objects between threads
The root cause is that trait objects \(\`dyn Trait\`\) do not automatically implement \`Send\`/\`Sync\` even if the underlying type does, and async blocks often capture lifetimes making them \`\!Send\`. The fix is to add explicit \`\+ Send\` bounds to the trait object: \`Box\`. For async traits, use \`\#\[async\_trait\]\` with Send bounds, or native \`async fn\` in traits with \`-> impl Future \+ Send\`.
Journey Context:
Developer is building a web server with Tokio. They define a trait \`Repository\` and want to store \`Box\` in \`AppState\` shared across tasks. They try to spawn a task: \`tokio::spawn\(async move \{ state.repo.get\(\).await \}\)\`. Compiler errors with \`dyn Repository cannot be sent between threads safely\`. They try adding \`Send\` to the struct but the trait object itself lacks the bound. They realize they need \`Box\`. They change the field type and ensure implementations are \`Send\`. Now \`tokio::spawn\` accepts the future because the trait object is marked \`Send\`, allowing the task to move between threads.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:57:07.737892+00:00— report_created — created