Skip to content

Sendable type cannot be sent between threads safely #135577

Open
@vklachkov

Description

@vklachkov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions