Closed
Description
fn foo() -> BoxFuture<'static, i32> {
async {
42
}
}
gives
error[E0308]: mismatched types
--> src/lib.rs:5:5
|
4 | fn foo() -> BoxFuture<'static, i32> {
| ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn core::future::future::Future<Output = i32> + std::marker::Send + 'static)>>` because of return type
5 | / async {
6 | | 42
7 | | }
| |_____^ expected struct `std::pin::Pin`, found opaque type
|
= note: expected type `std::pin::Pin<std::boxed::Box<(dyn core::future::future::Future<Output = i32> + std::marker::Send + 'static)>>`
found type `impl core::future::future::Future`
The expected struct std::pin::Pin
in particular is confusing. This can be a pretty intimidating error message for someone new to async/await, when all they forgot was .boxed()
.
I'm not sure if we can fix this without stabilizing BoxFuture
so we can sprinkle some magic compiler dust on its error messages. Maybe there's something we can do, though. Maybe some intelligent use of type aliases in our error messages?
cc @JakeEhrlich
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsAsync-await issues that have been triaged during a working group meeting.Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done