Skip to content

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

@SNCPlay42

Description

@SNCPlay42
Contributor
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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
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.
on Jan 3, 2021
added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jan 5, 2021
self-assigned this
on Jan 7, 2021
added
AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
on Jan 7, 2021
nellshamrell

nellshamrell commented on Jan 10, 2021

@nellshamrell
Contributor

Looks like #66463 touched areas of code that are relevant to this issue (not to say that it caused the issue, only that it provides a potential pointer to the parts of the code related to generating this error message)

tmandry

tmandry commented on Jan 28, 2021

@tmandry
Member

@nellshamrell Are you still planning to work on this? If not no worries, feel free to release your assignment.

added a commit that references this issue on Feb 26, 2021
aad8917
added 2 commits that reference this issue on Feb 26, 2021
3ddc7d4
a56bbb1
henryboisdequin

henryboisdequin commented on Mar 11, 2021

@henryboisdequin
Contributor

Can't this issue be closed (#82165) or is there still more work to be done?

22 remaining items

nellshamrell

nellshamrell commented on Jun 29, 2021

@nellshamrell
Contributor

I've opened a PR with at least a partial fix for this issue: #86705

eholk

eholk commented on Nov 21, 2022

@eholk
Contributor

Is this still an issue?

The current output for the test case (playground) is:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/lib.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
note: while checking the return type of the `async fn`
 --> src/lib.rs:2:28
  |
2 |     async fn async_fn() -> u8 {  22 }
  |                            ^^ checked the `Output` of this `async fn`, found opaque type
  = note:     expected type `u8`
          found opaque type `impl Future<Output = u8>`
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

which looks pretty close to the desired output listed above.

vincenzopalazzo

vincenzopalazzo commented on Dec 8, 2022

@vincenzopalazzo
Member

@rustbot claim

I will take a look as discussed in one of the async team meeting

moved this to Claimed in wg-async workon Dec 8, 2022
moved this from Claimed to In progress (current sprint) in wg-async workon Feb 7, 2023
added a commit that references this issue on Feb 13, 2023
73b022b
moved this from In progress (current sprint) to Done in wg-async workon Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

    Participants

    @eholk@nikomatsakis@nellshamrell@tmandry@SNCPlay42

    Issue actions

      Note when opaque future from `async fn` is involved in a type mismatch is unclear · Issue #80658 · rust-lang/rust