Skip to content

Note when opaque future from async fn is involved in a type mismatch is unclear #80658

Closed

Description

fn foo() -> u8 {
    async fn async_fn() -> () {}
    
    async_fn()
}

emits

error[E0308]: mismatched types
 --> src/lib.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
2 |     async fn async_fn() -> () {}
  |                            -- the `Output` of this `async fn`'s found opaque type
3 |
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
  = note:     expected type `u8`
          found opaque type `impl Future`

The note "the Output of this async fn's found opaque type" is kind of hard to understand. If the return type of async_fn isn't explicitly given, it doesn't even point at a type:

2 |     async fn async_fn() {}
  |                         - the `Output` of this `async fn`'s found opaque type

Perhaps the note should instead look like this:

2 |     async fn async_fn() {}
  |     ----- the found opaque type is the `impl Future` returned by this `async fn`

@rustbot label A-async-await A-diagnostics D-confusing T-compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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.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