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 "one type is more general than the other" (expected async block, found that same async block) when demanding an impl Send #126549

Closed
theemathas opened this issue Jun 16, 2024 · 1 comment
Labels
C-bug Category: This is a bug.

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 { }.then(|_| async { &THING })];
    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[E0308]: mismatched types
  --> src/lib.rs:4:5
   |
4  |     foo()
   |     ^^^^^ one type is more general than the other
...
10 |     let updates = [async { }.then(|_| async { &THING })];
   |                                       ----------------
   |                                       |
   |                                       the expected `async` block
   |                                       the found `async` block
   |
   = note: expected `async` block `{async block@src/lib.rs:10:39: 10:55}`
              found `async` block `{async block@src/lib.rs:10:39: 10:55}`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

See also #126551, 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 "one type is more general than the other" (expected async block, found that same async block) Async code causes error "one type is more general than the other" (expected async block, found that same async block) when demanding an impl Send Jun 16, 2024
@theemathas
Copy link
Contributor Author

theemathas commented Jun 16, 2024

Closing in favor of duplicated #126550

@theemathas theemathas closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants