rust
async_error
ai_generated
true
future cannot be sent between threads safely because `Rc<T>` does not implement `Send`
ID: rust/rust-async-send-bound
83%Fix Rate
87%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Async runtimes like tokio require futures to be Send. Non-Send types (Rc, Cell) held across await points cause this error.
genericWorkarounds
-
91% success Replace Rc with Arc and RefCell with Mutex/RwLock
use std::sync::Arc; use tokio::sync::Mutex; let shared = Arc::new(Mutex::new(data));
-
80% success Use tokio::task::spawn_local for single-threaded execution
let local = tokio::task::LocalSet::new(); local.run_until(async { tokio::task::spawn_local(my_future).await }).await;Sources: https://docs.rs/tokio/latest/tokio/task/struct.LocalSet.html
Dead Ends
Common approaches that don't work:
-
Wrap non-Send type in unsafe impl Send
92% fail
Data races will occur because the type is intentionally not Send for safety
-
Use tokio::task::spawn_blocking to bypass Send requirement
65% fail
spawn_blocking still requires Send for the closure; only the inner code can be non-async
Error Chain
Preceded by:
Frequently confused with: