Skip to content

Confusing error message when expecting BoxFuture #68197

Closed
@tmandry

Description

@tmandry

Playground

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

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions