rust-lang / rust-lang/rust

Sendable type cannot be sent between threads safely

Open
#135,577 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.