rust/compiler
bors 497c9a256b Auto merge of #80517 - wabain:issue-77880-infer-error-try-conversion-msg, r=davidtwco
Enhance type inference errors involving the `?` operator

This patch adds a special-cased note on type inference errors when the error span points to a `?` return. It also makes the primary label for such errors "cannot infer type of `?` error" in cases where before we would have only said "cannot infer type".

One beneficiary of this change is async blocks, where we can't explicitly annotate the return type and so may not generate any other help (#77880); this lets us at least print the error type we're converting from and anything we know about the type we can't fully infer. More generally, it signposts that an implicit conversion is happening that may have impeded type inference the user was expecting. We already do something similar for [mismatched type errors](2987785df3/src/test/ui/try-block/try-block-bad-type.stderr (L7)).

The check for a relevant `?` operator is built into the existing HIR traversal which looks for places that could be annotated to resolve the error. That means we could identify `?` uses anywhere in the function that output the type we can't infer, but this patch just sticks to adding the note if the primary span given for the error has the operator; if there are other expressions where the type occurs and one of them is selected for the error instead, it's more likely that the `?` operator's implicit conversion isn't the sole cause of the inference failure and that adding an additional diagnostic would just be noise. I added a ui test for one such case.

The data about the `?` conversion is passed around in a `UseDiagnostic` enum that in theory could be used to add more of this kind of note in the future. It was also just easier to pass around than something with a more specific name. There are some follow-up refactoring commits for the code that generates the error label, which was already pretty involved and made a bit more complicated by this change.
2021-01-12 14:42:37 +00:00
..
rustc
rustc_apfloat
rustc_arena stabilize min_const_generics 2020-12-26 18:24:10 +01:00
rustc_ast ast: Remove some indirection layers from values in key-value attributes 2021-01-09 21:50:39 +03:00
rustc_ast_lowering ast: Remove some indirection layers from values in key-value attributes 2021-01-09 21:50:39 +03:00
rustc_ast_passes Auto merge of #76580 - rokob:iss76011, r=estebank 2021-01-12 02:56:51 +00:00
rustc_ast_pretty ast: Remove some indirection layers from values in key-value attributes 2021-01-09 21:50:39 +03:00
rustc_attr
rustc_builtin_macros resolve: Simplify built-in macro table 2021-01-10 14:48:47 +03:00
rustc_codegen_cranelift Merge commit 'dbee13661efa269cb4cd57bb4c6b99a19732b484' into sync_cg_clif-2020-12-27 2020-12-27 10:30:38 +01:00
rustc_codegen_llvm Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_codegen_ssa Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_data_structures Serialize incr comp structures to file via fixed-size buffer 2021-01-11 12:13:22 -08:00
rustc_driver driver: Use atty instead of rolling our own 2021-01-11 19:59:25 -08:00
rustc_error_codes Refine E0435 description 2021-01-07 20:20:58 +09:00
rustc_errors Rollup merge of #79757 - jryans:long-line-tab-handling-early-expand, r=estebank 2021-01-12 16:13:15 +09:00
rustc_expand Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_feature Allow #[rustc_builtin_macro = "name"]. 2021-01-09 19:50:06 +01:00
rustc_fs_util Optimize away a fs::metadata call. 2021-01-06 08:33:15 -08:00
rustc_graphviz remove redundant closures (clippy::redundant_closure) 2021-01-03 13:34:24 +01:00
rustc_hir Rollup merge of #80538 - JulianKnodt:err_usize, r=lcnr 2021-01-05 09:52:37 +09:00
rustc_hir_pretty rustc_ast_pretty: Remove PrintState::insert_extra_parens 2021-01-08 00:43:38 +03:00
rustc_incremental Serialize incr comp structures to file via fixed-size buffer 2021-01-11 12:13:22 -08:00
rustc_index
rustc_infer Tweak ? inference error messages 2021-01-10 19:48:11 -05:00
rustc_interface Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obk 2021-01-12 07:59:13 +09:00
rustc_lexer Return EOF_CHAR constant instead of magic char. 2021-01-07 13:20:04 +01:00
rustc_lint Auto merge of #79414 - sasurau4:feature/add-suggestion-for-pattern-in-fns-without-body, r=matthewjasper 2021-01-10 20:48:27 +00:00
rustc_lint_defs Auto merge of #79414 - sasurau4:feature/add-suggestion-for-pattern-in-fns-without-body, r=matthewjasper 2021-01-10 20:48:27 +00:00
rustc_llvm
rustc_macros rustc_serialize: specialize opaque encoding of some u8 sequences 2021-01-01 22:49:14 -08:00
rustc_metadata Serialize incr comp structures to file via fixed-size buffer 2021-01-11 12:13:22 -08:00
rustc_middle Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_mir Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_mir_build Add note to non-exhaustive match on reference to empty 2021-01-03 19:05:23 +01:00
rustc_parse Auto merge of #76580 - rokob:iss76011, r=estebank 2021-01-12 02:56:51 +00:00
rustc_parse_format
rustc_passes Fix small typo 2021-01-10 21:24:32 -08:00
rustc_plugin_impl
rustc_privacy Fixed non-declarative-nor-opaque macros effective privacy. 2021-01-06 15:13:39 +01:00
rustc_query_system Don't mark force_query_with_job as inline(always) 2021-01-08 18:38:33 -05:00
rustc_resolve Rollup merge of #80927 - LingMan:matches, r=estebank 2021-01-12 16:13:33 +09:00
rustc_save_analysis reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats) 2021-01-02 20:09:17 +01:00
rustc_serialize rustc_serialize: fix incorrect signed LEB128 decoding 2021-01-11 12:13:26 -08:00
rustc_session Rollup merge of #79997 - coolreader18:wasm-reactor, r=alexcrichton 2021-01-12 07:58:59 +09:00
rustc_span Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00
rustc_symbol_mangling Rollup merge of #79968 - bjorn3:better_drop_glue_debuginfo, r=matthewjasper 2021-01-10 16:55:55 +09:00
rustc_target Rollup merge of #80042 - sivadeilra:cold_bits, r=oli-obk 2021-01-12 07:59:08 +09:00
rustc_trait_selection Note inference failures using ? conversion 2021-01-10 19:47:57 -05:00
rustc_traits fix: small typo error in chalk/mod.rs 2020-12-27 03:22:23 +01:00
rustc_ty_utils
rustc_type_ir
rustc_typeck Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank 2021-01-12 11:20:47 +00:00