Skip to content

Nellshamrell/improve async error#86705

Closed
nellshamrell wants to merge 6 commits intorust-lang:masterfrom
nellshamrell:nellshamrell/improve_async_error
Closed

Nellshamrell/improve async error#86705
nellshamrell wants to merge 6 commits intorust-lang:masterfrom
nellshamrell:nellshamrell/improve_async_error

Conversation

@nellshamrell
Copy link
Contributor

This is at least a partial fix for #80658

Prior to this fix, when someone attempted to compile this code:

fn main() {

}

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

    async_fn()
}

The would receive this output:

error[E0308]: mismatched types
 --> src/lib.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
2 |     async fn async_fn() -> u8 {  22 }
  |                            -- 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 std::future::Future`

If this change is merged, someone compiling the same code will then get this output instead:

error[E0308]: mismatched types
 --> src/lib.rs:8:5
  |
5 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
6 |     async fn async_fn() -> u8 {  22 }
  |                            -- calling an async function returns a future
7 |
8 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
  = note: while checking the return type of the `async fn`
  = note:     expected type `u8`
          found opaque type `impl Future`
help: consider `await`ing on the `Future`
  |
8 |     async_fn().await
  |               ^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

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

Labels

A-async-await Area: Async & Await S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants