rust/tests/ui/typeck
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
..
auxiliary
issue-87181
assign-non-lval-derefmut.fixed
assign-non-lval-derefmut.rs
assign-non-lval-derefmut.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
assign-non-lval-mut-ref.fixed
assign-non-lval-mut-ref.rs
assign-non-lval-mut-ref.stderr
assign-non-lval-needs-deref.rs
assign-non-lval-needs-deref.stderr
autoderef-with-param-env-error.rs
autoderef-with-param-env-error.stderr
bad-type-in-vec-push.rs
bad-type-in-vec-push.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
call-block.rs
call-block.stderr
check-args-on-fn-err-2.rs
check-args-on-fn-err-2.stderr
check-args-on-fn-err.rs
check-args-on-fn-err.stderr
conversion-methods.rs
conversion-methods.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
deref-multi.rs
deref-multi.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
do-not-suggest-adding-missing-zero-to-floating-point-number.rs
do-not-suggest-adding-missing-zero-to-floating-point-number.stderr
do-not-suggest-placeholder-to-const-static-without-type.rs
do-not-suggest-placeholder-to-const-static-without-type.stderr
explain_clone_autoref.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
explain_clone_autoref.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-10401.rs
issue-10401.stderr
issue-10969.rs
issue-10969.stderr
issue-13853-2.rs
issue-13853-2.stderr
issue-13853-5.rs
issue-13853-5.stderr
issue-13853.rs
issue-13853.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-18937-1.rs
issue-18937.rs
issue-18937.stderr
issue-22375.rs
issue-29124.rs
issue-29124.stderr
issue-31173.rs
issue-31173.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-33575.rs
issue-33575.stderr
issue-36708.rs
issue-36708.stderr
issue-43189.rs
issue-43189.stderr
issue-46112.rs
issue-46112.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-50687-ice-on-borrow.rs
issue-50687-ice-on-borrow.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-52082-type-param-shadows-existing-type.rs
issue-52082-type-param-shadows-existing-type.stderr
issue-55810-must-typeck-match-pats-before-guards.rs
issue-57404.rs
issue-57404.stderr
issue-57673-ice-on-deref-of-boxed-trait.rs
issue-57673-ice-on-deref-of-boxed-trait.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-61711-once-caused-rustc-inf-loop.rs
issue-65611.rs
issue-65611.stderr
issue-67971.rs
issue-67971.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-68590-reborrow-through-derefmut.rs
issue-69378-ice-on-invalid-type-node-after-recovery.rs
issue-69378-ice-on-invalid-type-node-after-recovery.stderr
issue-72225-call-fnmut-through-derefmut.rs
issue-73592-borrow_mut-through-deref.fixed
issue-73592-borrow_mut-through-deref.rs
issue-73592-borrow_mut-through-deref.stderr
issue-74086.rs
issue-74086.stderr
issue-74933.rs
issue-75883.rs
issue-75883.stderr
issue-75889.rs
issue-75889.stderr
issue-79040.rs
issue-79040.stderr
issue-80207-unsized-return.rs
issue-80779.rs
issue-80779.stderr
issue-81293.rs
issue-81293.stderr
issue-81885.rs
issue-81885.stderr
issue-81943.rs
issue-81943.stderr
issue-82772.rs
issue-82772.stderr
issue-83621-placeholder-static-in-extern.rs
issue-83621-placeholder-static-in-extern.stderr
issue-83693.rs
issue-83693.stderr
issue-84160.rs
issue-84160.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-84768.rs
issue-84768.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-84831.rs
issue-84831.stderr
issue-86721-return-expr-ice.rev1.stderr
issue-86721-return-expr-ice.rev2.stderr
issue-86721-return-expr-ice.rs
issue-87771-ice-assign-assign-to-bool.rs
issue-87771-ice-assign-assign-to-bool.stderr
issue-87872-missing-inaccessible-field-literal.rs
issue-87872-missing-inaccessible-field-literal.stderr
issue-87872-missing-inaccessible-field-pattern.rs
issue-87872-missing-inaccessible-field-pattern.stderr
issue-87935-unsized-box-expr.rs
issue-87935-unsized-box-expr.stderr
issue-88609.rs
issue-88643.rs
issue-88643.stderr
issue-88803-call-expr-method.fixed
issue-88803-call-expr-method.rs
issue-88803-call-expr-method.stderr
issue-88844.rs
issue-88844.stderr
issue-89044-wrapped-expr-method.fixed
issue-89044-wrapped-expr-method.rs
issue-89044-wrapped-expr-method.stderr
issue-89275.rs
issue-89275.stderr
issue-89806.rs
issue-89806.stderr
issue-89856.fixed Fix suggestion for coercing Option<&String> to Option<&str> 2023-02-03 11:44:23 +00:00
issue-89856.rs Fix suggestion for coercing Option<&String> to Option<&str> 2023-02-03 11:44:23 +00:00
issue-89856.stderr Fix suggestion for coercing Option<&String> to Option<&str> 2023-02-03 11:44:23 +00:00
issue-89935.rs
issue-90027-async-fn-return-suggestion.rs Suggest return type for async function without return type 2023-02-06 13:02:04 +08:00
issue-90027-async-fn-return-suggestion.stderr fix: improve the suggestion on future not awaited 2023-02-13 16:23:23 +01:00
issue-90101.rs
issue-90101.stderr
issue-90164.rs
issue-90164.stderr
issue-90319.rs
issue-90319.stderr
issue-90483-inaccessible-field-adjustment.rs
issue-90483-inaccessible-field-adjustment.stderr
issue-90804-incorrect-reference-suggestion.rs
issue-90804-incorrect-reference-suggestion.stderr
issue-91210-ptr-method.fixed
issue-91210-ptr-method.rs
issue-91210-ptr-method.stderr
issue-91267.rs
issue-91267.stderr
issue-91328.fixed
issue-91328.rs
issue-91328.stderr
issue-91334.rs
issue-91334.stderr Improve unexpected close and mismatch delimiter hint in TokenTreesReader 2023-01-27 17:45:41 +08:00
issue-91450-inner-ty-error.rs
issue-91450-inner-ty-error.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-91633.rs
issue-92481.rs
issue-92481.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-93486.rs
issue-93486.stderr
issue-96530.rs
issue-96530.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-96738.rs
issue-96738.stderr
issue-98260.rs
issue-98260.stderr
issue-98982.rs
issue-98982.stderr
issue-100164.fixed
issue-100164.rs
issue-100164.stderr
issue-100246.rs
issue-100246.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-100285.rs
issue-100285.stderr
issue-103899.rs
issue-104510-ice.rs
issue-104510-ice.stderr
issue-104513-ice.rs
issue-104513-ice.stderr
issue-104582.rs
issue-104582.stderr
issue-105946.rs
issue-105946.stderr
issue-107087.rs
issue-107087.stderr
issue-107775.rs Remove astconv usage in diagnostic 2023-02-07 23:08:25 +00:00
issue-107775.stderr Remove astconv usage in diagnostic 2023-02-07 23:08:25 +00:00
missing-private-fields-in-struct-literal.rs
missing-private-fields-in-struct-literal.stderr
no-type-for-node-ice.rs
no-type-for-node-ice.stderr
nonexistent-field-not-ambiguous.rs
nonexistent-field-not-ambiguous.stderr
path-to-method-sugg-unresolved-expr.rs
path-to-method-sugg-unresolved-expr.stderr
point-at-type-param-in-path-expr.rs
point-at-type-param-in-path-expr.stderr
point-at-type-parameter-definition.rs
point-at-type-parameter-definition.stderr
prim-with-args.fixed
prim-with-args.rs
prim-with-args.stderr
project-cache-issue-37154.rs
quiet-type-err-let-binding.rs
quiet-type-err-let-binding.stderr
remove-extra-argument.fixed
remove-extra-argument.rs
remove-extra-argument.stderr
return_type_containing_closure.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
return_type_containing_closure.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
slow-lhs-suggestion.rs
slow-lhs-suggestion.stderr
struct-enum-wrong-args.rs
struct-enum-wrong-args.stderr
suggest-adding-missing-zero-to-floating-point-number.fixed
suggest-adding-missing-zero-to-floating-point-number.rs
suggest-adding-missing-zero-to-floating-point-number.stderr
type-placeholder-fn-in-const.rs
type-placeholder-fn-in-const.stderr
typeck_type_placeholder_1.rs
typeck_type_placeholder_item_help.rs
typeck_type_placeholder_item_help.stderr
typeck_type_placeholder_item.rs
typeck_type_placeholder_item.stderr
typeck_type_placeholder_lifetime_1.rs
typeck_type_placeholder_lifetime_1.stderr
typeck_type_placeholder_lifetime_2.rs
typeck_type_placeholder_lifetime_2.stderr
typeck_type_placeholder_mismatch.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
typeck_type_placeholder_mismatch.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
typeck-builtin-bound-type-parameters.rs
typeck-builtin-bound-type-parameters.stderr
typeck-cast-pointer-to-float.rs
typeck-cast-pointer-to-float.stderr
typeck-closure-to-unsafe-fn-ptr.rs
typeck-default-trait-impl-assoc-type.fixed
typeck-default-trait-impl-assoc-type.rs
typeck-default-trait-impl-assoc-type.stderr
typeck-default-trait-impl-cross-crate-coherence.rs
typeck-default-trait-impl-cross-crate-coherence.stderr
typeck-default-trait-impl-negation-send.rs
typeck-default-trait-impl-negation-send.stderr
typeck-default-trait-impl-negation-sync.rs
typeck-default-trait-impl-negation-sync.stderr
typeck-default-trait-impl-send-param.rs
typeck-default-trait-impl-send-param.stderr
typeck-fn-to-unsafe-fn-ptr.rs
typeck-unsafe-always-share.rs
typeck-unsafe-always-share.stderr
ufcs-type-params.rs
unify-return-ty.rs
while-loop-block-cond.rs
while-loop-block-cond.stderr