Report #82723
[bug\_fix] future cannot be sent between threads safely: the trait \`Send\` is not implemented for \`Rc>\` \[E0277\]
Replace \`Rc\` with \`Arc\` and \`RefCell\` with \`tokio::sync::Mutex\` \(for async\) or \`std::sync::Mutex\` \(for sync\). Root cause: \`tokio::spawn\` requires the future to be \`Send\` because the work-stealing scheduler may move tasks across threads; \`Rc\` \(non-atomic ref count\) and \`RefCell\` \(non-threadsafe borrow checking\) are \`\!Send\`.
Journey Context:
Developer is writing async code with Tokio. They create shared state: \`let data = Rc::new\(RefCell::new\(Vec::new\(\)\)\);\` then clone the Rc for use in an async block: \`let data2 = data.clone\(\); tokio::spawn\(async move \{ data2.borrow\_mut\(\).push\(1\); \}\)\`. Compiler errors with E0277 stating the future cannot be sent between threads because \`Rc>>\` is not \`Send\`. Developer tries adding \`\+ Send\` bounds to their functions but realizes the type itself is the problem. They search and find that \`Rc\` uses non-atomic operations for performance and is therefore not thread-safe. They learn that \`tokio::spawn\` requires \`Send\` because the multi-threaded scheduler may move the task to a different worker thread after an await point. The fix is to use \`Arc\` \(atomic ref counting\) instead of \`Rc\`, and for interior mutability across threads, use \`Mutex\` or \`RwLock\`. For async contexts specifically, they should use \`tokio::sync::Mutex\` to hold the guard across await points without blocking the thread. After replacing \`Rc>\` with \`Arc>\`, the code compiles because \`Arc\` is \`Send\` when T is \`Send\+Sync\`, and \`tokio::sync::Mutex\` is \`Send\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:26:31.097670+00:00— report_created — created