Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bogus "implementation of <whatever trait you want> is not general enough" with RPITIT + async #130113

Open
Tracked by #110338
jplatte opened this issue Sep 8, 2024 · 1 comment
Labels
A-async-await Area: Async & Await A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Sep 8, 2024

I tried this code:

use std::future::Future;

fn bug() {
    let call_me = Wrap(CallMeImpl { value: "test" });

    assert_send(async {
        call_me.call().await;
    });
}

pub fn assert_send<F>(_future: F)
where
    F: Future + Send,
{
}

pub trait CallMe {
    fn call(&self) -> impl Future<Output = ()> + Send;
}

struct Wrap<T>(T);

impl<S> CallMe for Wrap<S>
where
    S: CallMe + Send,
{
    // adding `+ Send` to this RPIT fixes the issue
    fn call(&self) -> impl Future<Output = ()> {
        self.0.call()
    }
}

#[derive(Debug, Clone, Copy)]
pub struct CallMeImpl<T> {
    value: T,
}

impl<T> CallMe for CallMeImpl<T>
where
    // Can replace `Send` by `ToString`, `Clone`, whatever. When removing the
    // `Send` bound, the compiler produces a higher-ranked lifetime error.
    T: Send + 'static,
{
    fn call(&self) -> impl Future<Output = ()> {
        async {}
    }
}

I expected to see this happen: Compile successfully

Instead, this happened:

error: implementation of `Send` is not general enough
 --> src/lib.rs:6:5
  |
6 | /     assert_send(async {
7 | |         call_me.call().await;
8 | |     });
  | |______^ implementation of `Send` is not general enough
  |
  = note: `Send` would have to be implemented for the type `&'0 str`, for any lifetime `'0`...
  = note: ...but `Send` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (9c01301c5 2024-09-05)
binary: rustc
commit-hash: 9c01301c52df5d2d7b6fe337707a74e011d68d6f
commit-date: 2024-09-05
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

happens with stable too.

I found a lot of similar-looking issues in #110338, but none quite like this one, so I chose to report a new one instead. Maybe I overlooked an existing bug report though, sorry if I did!

@jplatte jplatte added the C-bug Category: This is a bug. label Sep 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 8, 2024
@jplatte jplatte changed the title Bogus "implementation of <whatever trait you want> is not general enough" with RPITIT Bogus "implementation of <whatever trait you want> is not general enough" with RPITIT + async Sep 8, 2024
@lolbinarycat lolbinarycat added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await A-trait-system Area: Trait system A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 8, 2024
@eholk
Copy link
Contributor

eholk commented Oct 3, 2024

While not exactly the same, it seems substantially similar enough to #110338 so I added this to the list.

@traviscross traviscross changed the title Bogus "implementation of <whatever trait you want> is not general enough" with RPITIT + async Bogus "implementation of <whatever trait you want> is not general enough" with RPITIT + async Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants