b3e76aa491
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. |
||
---|---|---|
.. | ||
rustc | ||
rustc_apfloat | ||
rustc_arena | ||
rustc_ast | ||
rustc_ast_lowering | ||
rustc_ast_passes | ||
rustc_ast_pretty | ||
rustc_attr | ||
rustc_borrowck | ||
rustc_builtin_macros | ||
rustc_codegen_cranelift | ||
rustc_codegen_gcc | ||
rustc_codegen_llvm | ||
rustc_codegen_ssa | ||
rustc_const_eval | ||
rustc_data_structures | ||
rustc_driver | ||
rustc_error_codes | ||
rustc_error_messages | ||
rustc_errors | ||
rustc_expand | ||
rustc_feature | ||
rustc_fs_util | ||
rustc_graphviz | ||
rustc_hir | ||
rustc_hir_pretty | ||
rustc_incremental | ||
rustc_index | ||
rustc_infer | ||
rustc_interface | ||
rustc_lexer | ||
rustc_lint | ||
rustc_lint_defs | ||
rustc_llvm | ||
rustc_log | ||
rustc_macros | ||
rustc_metadata | ||
rustc_middle | ||
rustc_mir_build | ||
rustc_mir_dataflow | ||
rustc_mir_transform | ||
rustc_monomorphize | ||
rustc_parse | ||
rustc_parse_format | ||
rustc_passes | ||
rustc_plugin_impl | ||
rustc_privacy | ||
rustc_query_impl | ||
rustc_query_system | ||
rustc_resolve | ||
rustc_save_analysis | ||
rustc_serialize | ||
rustc_session | ||
rustc_smir | ||
rustc_span | ||
rustc_symbol_mangling | ||
rustc_target | ||
rustc_trait_selection | ||
rustc_traits | ||
rustc_transmute | ||
rustc_ty_utils | ||
rustc_type_ir | ||
rustc_typeck |