Report #54521
[bug\_fix] future cannot be sent between threads safely \(E0277\) when spawning an async block with \`tokio::spawn\` containing \`Rc\` or non-Send types
Replace \`Rc\` with \`Arc\` \(which is Send\+Sync\), ensure all captured variables in the async block implement \`Send\`, or use \`tokio::task::LocalSet\` to spawn \!Send futures on a single thread. Root cause: \`tokio::spawn\` \(and the standard library's thread spawning\) requires the future to be \`'static \+ Send\` so it can be safely transferred to another thread for execution; \`Rc\` uses non-atomic ref counting and is not thread-safe \(not Send\).
Journey Context:
A developer is converting a synchronous single-threaded app to async using Tokio. They wrap their state in \`Rc>\` and try to spawn a task: \`tokio::spawn\(async move \{ let state = rc\_state.clone\(\); ... \}\)\`. The compiler emits a long E0277 error: "future cannot be sent between threads safely ... because \`Rc\` is not \`Send\`". The developer initially tries to add \`\+ Send\` bounds to their functions, but realizes the issue is the \`Rc\` itself. They search and find that \`Rc\` is intentionally single-threaded for performance. They replace \`Rc\` with \`Arc\` and \`RefCell\` with \`RwLock\` \(or \`Mutex\`\). After changing types, the \`tokio::spawn\` compiles. They understand that async executors may move tasks across threads, requiring Send bounds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:00:38.229663+00:00— report_created — created