Skip to content

Incorrect "implementation of Send is not general enough" error with lifetimed Send impl used in async fn #96865

Open
@SabrinaJewson

Description

@SabrinaJewson

I tried this code:

struct Foo<'a, F> {
    func: F,
    data: &'a u32,
}
unsafe impl<'a, F: Send + Callback<&'a u32>> Send for Foo<'a, F> {}

trait Callback<I> {}

struct Implementor<'a>(&'a u32);
impl<'a> Callback<&'a u32> for Implementor<'a> {}

fn assert_send<T: Send>(v: T) -> T { v }

async fn async_function<'a>(data: &'a u32) {
    let data = assert_send(Foo {
        func: Implementor(data),
        data,
    });
    std::future::ready(5).await;
}

fn wrapper(data: &u32) {
    assert_send(async_function(data));
}

I expected to see this happen: No error

Instead, this happened:

error: implementation of `std::marker::Send` is not general enough
  --> src/main.rs:23:5
   |
23 |     assert_send(async_function(data));
   |     ^^^^^^^^^^^ implementation of `std::marker::Send` is not general enough
   |
   = note: `std::marker::Send` would have to be implemented for the type `Foo<'0, Implementor<'1>>`, for any two lifetimes `'0` and `'1`...
   = note: ...but `std::marker::Send` is actually implemented for the type `Foo<'2, Implementor<'_>>`, for some specific lifetime `'2`

Meta

rustc --version --verbose:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Also happens with Nightly:

rustc 1.62.0-nightly (bed05e996 2022-05-02)
binary: rustc
commit-hash: bed05e996e37e44b1a3980b84754af621fd3c4ce
commit-date: 2022-05-02
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    On deck

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions