rust/compiler
Michael Goulet b3e76aa491
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
Argument type error improvements

Motivated by this interesting code snippet:

```rust
#[derive(Copy, Clone)]
struct Wrapper<T>(T);

fn foo(_: fn(i32), _: Wrapper<i32>) {}

fn f(_: u32) {}

fn main() {
    let w = Wrapper::<isize>(1isize);
    foo(f, w);
}
```

Which currently errors like:
```
error[E0308]: arguments to this function are incorrect
  --> src/main.rs:10:5
   |
10 |     foo(f, w);
   |     ^^^ -  - expected `i32`, found `isize`
   |         |
   |         expected `i32`, found `u32`
   |
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> src/main.rs:4:4
   |
4  | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------
```

Specifically, that double `expected .. found ..` which is very difficult to correlate to the types in the arguments. Also, the fact that "expected `i32`, found `isize`" and the other argument mismatch label don't even really explain what's going on here.

After this PR:
```
error[E0308]: arguments to this function are incorrect
  --> $DIR/two-mismatch-notes.rs:10:5
   |
LL |     foo(f, w);
   |     ^^^
   |
note: expected fn pointer, found fn item
  --> $DIR/two-mismatch-notes.rs:10:9
   |
LL |     foo(f, w);
   |         ^
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
note: expected struct `Wrapper`, found a different struct `Wrapper`
  --> $DIR/two-mismatch-notes.rs:10:12
   |
LL |     foo(f, w);
   |            ^
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> $DIR/two-mismatch-notes.rs:4:4
   |
LL | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------

error: aborting due to previous error

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

Yeah, it's a bit verbose, but much clearer IMO.

---

Open to discussions about how this could be further improved. Motivated by `@jyn514's` [tweet](https://mobile.twitter.com/joshuayn514/status/1558042020601634816) here.
2022-08-13 21:06:53 -07:00
..
rustc
rustc_apfloat Warn about dead tuple struct fields 2022-08-03 12:17:23 +02:00
rustc_arena Stabilize ptr_const_cast 2022-08-10 17:22:58 +02:00
rustc_ast Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_ast_lowering Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_ast_passes Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_ast_pretty Rollup merge of #100350 - jhpratt:stringify-vis, r=cjgillot 2022-08-11 22:53:06 +02:00
rustc_attr Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_borrowck Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_builtin_macros Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_codegen_cranelift also update anyhow in codegen_cranelift 2022-08-08 09:04:26 -04:00
rustc_codegen_gcc Introduce an ArchiveBuilderBuilder 2022-07-28 09:08:47 +00:00
rustc_codegen_llvm Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_codegen_ssa Rollup merge of #99500 - tmandry:fuchsia-flags, r=petrochenkov 2022-08-11 22:52:59 +02:00
rustc_const_eval Rollup merge of #100438 - compiler-errors:issue-100360, r=lcnr 2022-08-13 14:10:07 -07:00
rustc_data_structures remove some manual hash stable impls 2022-07-29 12:48:28 +02:00
rustc_driver Error on broken pipe but do not ICE 2022-08-02 01:08:50 +01:00
rustc_error_codes region_outlives_predicate no snapshot 2022-07-21 13:09:01 +02:00
rustc_error_messages Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_errors Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_expand Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_feature Rollup merge of #96478 - WaffleLapkin:rustc_default_body_unstable, r=Aaron1011 2022-08-09 17:34:50 +05:30
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillot 2022-08-11 22:53:08 +02:00
rustc_hir_pretty Fix HIR pretty printing of let else 2022-08-12 02:47:57 +00:00
rustc_incremental Remove trait_of_item query. 2022-08-01 21:39:26 +02:00
rustc_index Auto merge of #99052 - tmiasko:bitset-clone-from, r=Mark-Simulacrum 2022-07-31 21:40:21 +00:00
rustc_infer Do not inline non-simple argument type errors into labels 2022-08-13 18:24:36 +00:00
rustc_interface Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_lexer Shrink Token. 2022-08-01 08:53:04 +10:00
rustc_lint Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_lint_defs Warn about dead tuple struct fields 2022-08-03 12:17:23 +02:00
rustc_llvm Link libatomic on 32-bit targets 2022-08-09 12:39:59 +02:00
rustc_log
rustc_macros dedupe 'annotate-snippets' crate versions 2022-08-02 21:07:01 +03:00
rustc_metadata Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_middle Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_mir_build Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_mir_dataflow Remove redundant TransferWrapper struct 2022-08-01 17:08:19 +02:00
rustc_mir_transform Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_monomorphize Use LocalDefId for closures more 2022-07-30 15:59:17 -05:00
rustc_parse Rollup merge of #100446 - TaKO8Ki:suggest-removing-semicolon-after-impl-trait-items, r=compiler-errors 2022-08-13 21:06:51 -07:00
rustc_parse_format add a comment about what we can parse now 2022-08-04 20:43:35 +09:00
rustc_passes Rollup merge of #100431 - compiler-errors:enum-ctor-variant-stab, r=estebank 2022-08-13 21:06:50 -07:00
rustc_plugin_impl
rustc_privacy Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_query_impl Use LocalDefId for closures more 2022-07-30 15:59:17 -05:00
rustc_query_system Remove useless closure. 2022-07-29 22:11:23 +02:00
rustc_resolve Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors 2022-08-13 21:06:49 -07:00
rustc_save_analysis Remove DefId from AssocItemContainer. 2022-08-01 21:38:45 +02:00
rustc_serialize
rustc_session Adjust cfgs 2022-08-12 16:28:15 -04:00
rustc_smir
rustc_span Rollup merge of #96478 - WaffleLapkin:rustc_default_body_unstable, r=Aaron1011 2022-08-09 17:34:50 +05:30
rustc_symbol_mangling Auto merge of #95548 - rcvalle:rust-cfi-2, r=nagisa 2022-07-24 01:22:36 +00:00
rustc_target Auto merge of #99464 - nikic:llvm-15, r=cuviper 2022-08-12 02:58:51 +00:00
rustc_trait_selection wf correctly shallow_resolve consts 2022-08-13 21:04:52 +02:00
rustc_traits Rollup merge of #100095 - jackh726:early-binder, r=lcnr 2022-08-04 22:25:04 +02:00
rustc_transmute safe transmute: fix broken intradoc link 2022-08-02 14:44:23 +00:00
rustc_ty_utils Add bound_impl_subject and bound_return_ty 2022-08-03 01:02:46 -04:00
rustc_type_ir Inline DebruijnIndex methods 2022-07-22 17:00:49 +02:00
rustc_typeck Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr 2022-08-13 21:06:53 -07:00