Sendable type cannot be sent between threads safely
Open
Nobody has claimed this yet.
C-enhancement
D-confusing
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::rc::Rc;
struct Unsendable(Rc<()>);
struct Sendable<T>(T);
unsafe impl<T> Send for Sendable<T> {}
impl<T> Sendable<T> {
#[inline(always)]
fn into_inner(self) -> T {
self.0
}
}
fn main() {
tokio::task::spawn({
let foo = Unsendable(Rc::new(()));
let foo = Sendable(foo);
async move {
let Sendable(foo) = foo;
// let foo = foo.into_inner();
}
});
}
If I replace line let Sendable(foo) = foo; with let foo = foo.into_inner(); the error disappears.
I create bigger example, without tokio. Rust Playground
I expected to see successful compilation
Instead I got error[E0277]: Rc<()> cannot be sent between threads safely
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust Playground reproducer and compare the destructuring form with the into_inner form. Trace how the compiler checks Send for the async block and its captured values. The work is done when the reported example compiles as expected without weakening Send safety, with a regression test covering the reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100