Description
Code
fn main() {
let a = async { 1 };
let b = async { 2 };
let bad = vec![a, b];
}
Current output
error[E0308]: mismatched types
--> src/main.rs:5:23
|
2 | let a = async { 1 };
| ----------- the expected `async` block
3 | let b = async { 2 };
| ----------- the found `async` block
4 |
5 | let bad = vec![a, b];
| ^ expected `async` block, found a different `async` block
|
= note: expected `async` block `{async block@src/main.rs:2:13: 2:24}`
found `async` block `{async block@src/main.rs:3:13: 3:24}`
For more information about this error, try `rustc --explain E0308`.
Desired output
error[E0308]: mismatched types
--> src/main.rs:5:23
|
2 | let a = async { 1 };
| ----------- the expected `async` block
3 | let b = async { 2 };
| ----------- the found `async` block
4 |
5 | let bad = vec![a, b];
| ^ <something better here!>
|
= note: expected `async` block `{async block@src/main.rs:2:13: 2:24}`
found `async` block `{async block@src/main.rs:3:13: 3:30}`
= note: the futures produced by async blocks always have unique types, even if
they have the same output type.
For more information about this error, try `rustc --explain E0308`.
Rationale and extra context
Especially for people new to async, this message is extremely opaque. There is not actually enough information to understand it unless you already know (a) that async blocks produce an anonymous future type and (b) that regardless of the Output
type, those futures are always unique and incompatible types. The message sort of implies this (“found a different async
block”), but it is not actionable in any way.
It is pretty easy to get here by reaching for (to pick just one easy example) futures::future::join_all
. I ended up stumbling across it in the process of building up some sample code for the new async chapter in the book, and I had a 🤨 moment at first!
I have the time to help fix this, so if someone can point me in the right direction and help get it landed, I would be delighted to do the work.
Other cases
No response
Rust Version
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: aarch64-apple-darwin
release: 1.77.1
LLVM version: 17.0.6
Anything else?
No response