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

Extremely un-informative error when a future that capture the environment is used as Send #126550

Open
Tracked by #110338
Ciel-MC 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

@Ciel-MC
Copy link

Ciel-MC commented Jun 16, 2024

Code

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

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

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

Current output

error[E0308]: mismatched types
  --> src/main.rs:12:5
   |
5  |       let updates = [async {}.then(|()| async move {
   |  _______________________________________-
6  | |         &THING
7  | |     })];
   | |     -
   | |     |
   | |_____the expected `async` block
   |       the found `async` block
...
12 |       foo()
   |       ^^^^^ one type is more general than the other
   |
   = note: expected `async` block `{async block@src/main.rs:5:39: 7:6}`
              found `async` block `{async block@src/main.rs:5:39: 7:6}`

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

Desired output

No response

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

(Happens on nightly too)

Anything else?

The code compiles without the reference, so I'm guessing it's to do with the Future being made "unique" by that even though it doesn't actually contain any "real" captures that should make the closure different.

@Ciel-MC Ciel-MC 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. labels Jun 16, 2024
@jieyouxu jieyouxu added A-async-await Area: Async & Await D-confusing Diagnostics: Confusing error or lint that should be reworked. 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