rust/tests/ui/async-await/in-trait
Vincenzo Palazzo 2bdc9a046a
fix: improve the suggestion on future not awaited
Considering the following code

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

    async_fn()
}

fn main() {}
```

the error generated before this commit from the compiler is

```
➜  rust git:(macros/async_fn_suggestion) ✗ rustc test.rs --edition 2021
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, 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
  |               ++++++

error: aborting due to previous error
```

In this case the error is nor perfect, and can confuse the user
that do not know that the opaque type is the future.

So this commit will propose (and conclude the work start in
https://github.com/rust-lang/rust/issues/80658)
to change the string `opaque type` to `future` when applicable
and also remove the Expected vs Received note by adding a more
specific one regarding the async function that return a future type.

So the new error emitted by the compiler is

```
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found future
  |
note: calling an async function returns a future
 --> test.rs:4:5
  |
4 |     async_fn()
  |     ^^^^^^^^^^
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-13 16:23:23 +01:00
..
async-associated-types2.rs
async-associated-types.rs
async-example-desugared-boxed-in-trait.rs
async-example-desugared-boxed-in-trait.stderr fix: improve the suggestion on future not awaited 2023-02-13 16:23:23 +01:00
async-example-desugared-boxed.rs
async-example-desugared-boxed.stderr
async-example-desugared-extra.rs
async-example-desugared-in-trait.rs
async-example-desugared-manual.rs
async-example-desugared-manual.stderr
async-example-desugared.rs
async-example.rs
async-generics-and-bounds.rs
async-generics-and-bounds.stderr
async-generics.rs
async-generics.stderr
async-lifetimes-and-bounds.rs
async-lifetimes.rs
async-recursive-generic.rs
async-recursive-generic.stderr
async-recursive.rs
async-recursive.stderr
bad-signatures.rs
bad-signatures.stderr
early-bound-1.rs
early-bound-2.rs
fn-not-async-err2.rs
fn-not-async-err2.stderr
fn-not-async-err.rs
fn-not-async-err.stderr
implied-bounds.rs
issue-102138.rs
issue-102219.rs
issue-102310.rs
issue-104678.rs
lifetime-mismatch.rs
lifetime-mismatch.stderr
missing-send-bound.rs
missing-send-bound.stderr
nested-rpit.rs Revert "Make nested RPITIT inherit the parent opaque's generics." and adjust test 2023-01-12 06:07:53 +00:00
object-safety.rs
object-safety.stderr
return-type-suggestion.rs
return-type-suggestion.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00