granite-rust/compiler
Matthias Krüger 73b022b8e1
Rollup merge of #107902 - vincenzopalazzo:macros/async_fn_suggestion, r=compiler-errors
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
```

Fixes https://github.com/rust-lang/rust/issues/80658

It remains to rework the case described in the following issue https://github.com/rust-lang/rust/issues/107899 but I think this deserves its own PR after we discuss a little bit how to handle these kinds of cases.

r? `@eholk`

`@rustbot` label +I-async-nominated

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-13 23:25:11 +01:00
..
rustc Add a new rustc_driver dylib to rexport rustc_driver_impl 2023-02-02 07:34:41 +01:00
rustc_abi also do not add noalias on not-Unpin Box 2023-02-06 12:17:41 +01:00
rustc_apfloat compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_arena compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_ast rustc_ast: Merge impls and reorder methods for attributes and meta items 2023-02-11 23:23:17 +04:00
rustc_ast_lowering remove unused imports 2023-02-06 17:40:18 +03:00
rustc_ast_passes Autoderive ExternBlockSuggestion 2023-01-19 13:52:15 +01:00
rustc_ast_pretty Expand const-if-const trait bounds correctly 2023-02-07 21:00:12 +00:00
rustc_attr Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_baked_icu_data Update crate documentation of rustc_baked_icu_data crate 2022-11-18 14:46:36 -08:00
rustc_borrowck Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
rustc_builtin_macros Extend BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE. 2023-02-09 11:47:12 +11:00
rustc_codegen_cranelift Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
rustc_codegen_gcc session: diagnostic migration lint on more fns 2023-01-30 17:11:35 +00:00
rustc_codegen_llvm Auto merge of #102963 - ilammy:xray-basic, r=estebank 2023-02-10 00:02:43 +00:00
rustc_codegen_ssa Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
rustc_const_eval Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
rustc_data_structures Resolve documentation links in rustc and store the results in metadata 2023-02-10 09:34:13 +04:00
rustc_driver Remove unneeded extern crate 2023-02-02 07:47:39 +01:00
rustc_driver_impl Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa 2023-02-13 11:34:57 +01:00
rustc_error_codes Add extended error message for E0523 2023-02-06 06:58:30 -05:00
rustc_error_messages Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkov 2023-02-12 07:15:27 +00:00
rustc_errors Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa 2023-02-13 11:34:57 +01:00
rustc_expand Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa 2023-02-13 11:34:57 +01:00
rustc_feature [link] enable packed bundled lib in non stable cases 2023-02-10 12:51:12 +03:00
rustc_fs_util Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_graphviz Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_hir Resolve documentation links in rustc and store the results in metadata 2023-02-10 09:34:13 +04:00
rustc_hir_analysis Rename folder traits' tcx method to interner 2023-02-13 10:24:51 +00:00
rustc_hir_pretty Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
rustc_hir_typeck Rename folder traits' tcx method to interner 2023-02-13 10:24:51 +00:00
rustc_incremental incremental: migrate diagnostics 2023-01-30 17:11:35 +00:00
rustc_index Fix IndexVec::drain_enumerated 2023-01-19 15:25:33 +00:00
rustc_infer Rollup merge of #107902 - vincenzopalazzo:macros/async_fn_suggestion, r=compiler-errors 2023-02-13 23:25:11 +01:00
rustc_interface Rollup merge of #107831 - nnethercote:query-refactoring, r=oli-obk 2023-02-10 06:09:57 +01:00
rustc_lexer Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
rustc_lint Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
rustc_lint_defs Extend BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE. 2023-02-09 11:47:12 +11:00
rustc_llvm llvm-16: Use Triple.h from new header location. 2023-02-07 06:51:58 -08:00
rustc_log Rollup merge of #107895 - matthiaskrgr:cl, r=compiler-errors 2023-02-11 17:18:44 +01:00
rustc_macros Make folding traits generic over the Interner 2023-02-13 10:24:49 +00:00
rustc_metadata Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkov 2023-02-12 07:15:27 +00:00
rustc_middle Rollup merge of #107902 - vincenzopalazzo:macros/async_fn_suggestion, r=compiler-errors 2023-02-13 23:25:11 +01:00
rustc_mir_build remove unused imports 2023-02-06 17:40:18 +03:00
rustc_mir_dataflow Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obk 2023-02-08 18:32:41 +01:00
rustc_mir_transform Auto merge of #107851 - cjgillot:sroa-const, r=oli-obk 2023-02-11 20:59:18 +00:00
rustc_monomorphize Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
rustc_parse Rollup merge of #107446 - clubby789:rustc-parse-diag-migrate, r=compiler-errors 2023-02-09 11:21:57 +01:00
rustc_parse_format remove redundant clones 2023-02-10 18:08:25 +01:00
rustc_passes rustc_passes: remove huge error imports 2023-02-05 03:47:58 +01:00
rustc_plugin_impl
rustc_privacy Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
rustc_query_impl Simplify tls::enter_context. 2023-02-09 15:25:45 +11:00
rustc_query_system Create a single value cache for the () query key 2023-02-11 23:38:01 +01:00
rustc_resolve Auto merge of #94857 - petrochenkov:doclink2, r=oli-obk 2023-02-11 12:10:16 +00:00
rustc_save_analysis Review changes 2023-01-31 07:54:01 +00:00
rustc_serialize compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_session Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa 2023-02-13 11:34:57 +01:00
rustc_smir
rustc_span Rollup merge of #107931 - cjgillot:issue-107353, r=WaffleLapkin 2023-02-13 11:34:58 +01:00
rustc_symbol_mangling Pre-intern some commonly used type variables. 2023-02-13 09:25:36 +11:00
rustc_target XRay support flag in TargetOptions 2023-02-09 12:28:01 +09:00
rustc_trait_selection Rename folder traits' tcx method to interner 2023-02-13 10:24:51 +00:00
rustc_traits Rename folder traits' tcx method to interner 2023-02-13 10:24:51 +00:00
rustc_transmute Also remove #![feature(control_flow_enum)] where possible 2023-01-18 10:22:21 -08:00
rustc_ty_utils layout: deal with placeholders, ICE on bound types 2023-02-13 10:47:12 +01:00
rustc_type_ir Rename folder traits' tcx method to interner 2023-02-13 10:24:51 +00:00