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

Async code causes error "implementation of FnOnce is not general enough" when demanding an impl Send #126551

Open
Tracked by #110338
theemathas opened this issue Jun 16, 2024 · 1 comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented Jun 16, 2024

Credit to @Ciel-MC for discovering this.

I tried this code:

use futures::prelude::future::{join_all, FutureExt};

fn foo_is_send() -> impl Send {
    foo()
}

static THING: () = ();

async fn foo() {
    let updates = [async { &THING }.then(|_| async {})];
    join_all(updates).await;
}

I expected the code to compile without errors. Instead, I got the following compile error:

   Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
 --> src/lib.rs:4:5
  |
4 |     foo()
  |     ^^^^^ implementation of `FnOnce` is not general enough
  |
  = note: closure with signature `fn(&'0 ()) -> {async block@src/lib.rs:10:46: 10:54}` must implement `FnOnce<(&'1 (),)>`, for any two lifetimes `'0` and `'1`...
  = note: ...but it actually implements `FnOnce<(&(),)>`

error: could not compile `playground` (lib) due to 1 previous error

Possibly related to #126044

See also #126550, which has similar reproduction code.

Meta

Tested on the playground with stable (1.79.0) and nightly (1.81.0-nightly (2024-06-15 3cf924b))

@theemathas theemathas added the C-bug Category: This is a bug. label Jun 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 16, 2024
@theemathas theemathas changed the title Async code causes error "implementation of FnOnce is not general enough" when demanding a Send Async code causes error "implementation of FnOnce is not general enough" when demanding an impl Send Jun 16, 2024
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await D-confusing Diagnostics: Confusing error or lint that should be reworked. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 16, 2024
@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged

We discussed this in the async meeting today. We think this is probably related to:

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jul 11, 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-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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