rust/compiler
Dylan DPC 7dc3ace6a9
Rollup merge of #103706 - zbyrn:issue-101637-fix, r=estebank
Fix E0433 No Typo Suggestions

Fixes #48676
Fixes #87791
Fixes #96625
Fixes #95462
Fixes #101637
Follows up PR #72923

Several open issues refer to the problem that E0433 does not suggest typos like other errors normally do. This fix augments the implementation of PR #72923.

**Background**
When the path of a function call, e.g. `Struct::foo()`, involves names that cannot be resolved, there are two errors that could be emitted by the compiler:
 - If `Struct` is not found, it is ``E0433: failed to resolve: use of undeclared type `Struct` ``.
 - If `foo` is not found in `Struct`, it is ``E0599: no function or associated item named `foo` found for struct `Struct` in the current scope``

When a name is used as a type, `e.g. fn foo() -> Struct`, and the name cannot be resolved, it is ``E0412: cannot find type `Struct` in this scope``.

Before #72923, `E0433` does not implement any suggestions, and the PR introduces suggestions for missing `use`s. When a resolution error occurs in the path of a function call, it tries to smart resolve just the type part of the path, e.g. `module::Struct` of a call to `module::Struct::foo()`. However, along with the suggestions, the smart-resolve function will report `E0412` since it only knows that it is a type that we cannot resolve instead of being a part of the path. So, the original implementation swap out `E0412` errors returned by the smart-resolve function with the real `E0433` error, but keeps the "missing `use`" suggestions to be reported to the programmer.

**Issue**
The current implementation only reports if there are "missing `use`" suggestions returned by the smart-resolve function; otherwise, it would fall back the normal reporting, which does not emit suggestions. But the smart-resolve function could also produce typo suggestions, which are omitted currently.

Also, it seems like that not all info has been swapped out when there are missing suggestions. The error message underlining the name in the snippet still says ``not found in this scope``, which is a `E0412` messages, if there are `use` suggestions, but says the normal `use of undeclared type` otherwise.

**Fixes**
This fix swaps out all fields in `Diagnostic` returned by the smart-resolve function except for `suggestions` with the current error, and merges the `suggestions` of the returned error and that of the current error together. If there are `use` suggestions, the error is saved to `use_injection` to be reported at the end; otherwise, the error is emitted immediately as `Resolver::report_error` does.

Some tests are updated to use the correct underlining error messages, and one additional test for typo suggestion is added to the test suite.

r? rust-lang/diagnostics
2022-11-01 14:12:26 +05:30
..
rustc rustc: Use unix_sigpipe instead of rustc_driver::set_sigpipe_handler 2022-10-02 17:49:36 +02:00
rustc_apfloat
rustc_arena
rustc_ast remove unused parser fn 2022-10-26 19:19:44 +00:00
rustc_ast_lowering Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors 2022-10-30 11:50:26 +05:30
rustc_ast_passes Rollup merge of #95710 - fee1-dead-contrib:stabilize_arbitrary_enum_discriminant, r=joshtriplett 2022-10-26 17:32:53 +05:30
rustc_ast_pretty Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
rustc_attr Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_borrowck Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_builtin_macros Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_codegen_cranelift Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_codegen_gcc Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_codegen_llvm Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_codegen_ssa Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_const_eval Rollup merge of #103798 - RalfJung:type_name, r=oli-obk 2022-11-01 12:03:43 +09:00
rustc_data_structures Introduce UnordMap, UnordSet, and UnordBag (see MCP 533) 2022-10-27 13:23:26 +00:00
rustc_driver Remove rustc_driver::set_sigpipe_handler() 2022-10-25 19:13:23 +02:00
rustc_error_codes Update E0382.md 2022-10-31 00:41:12 -04:00
rustc_error_messages Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3 2022-11-01 14:12:25 +05:30
rustc_errors Allow specifying multiple alternative suggestions 2022-10-23 18:59:13 +02:00
rustc_expand Rollup merge of #103544 - Nilstrieb:no-recovery-pls, r=compiler-errors 2022-10-27 15:03:58 +02:00
rustc_feature Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3 2022-11-01 14:12:25 +05:30
rustc_hir_analysis Rollup merge of #103603 - camsteffen:refactor-lang, r=oli-obk 2022-10-31 14:52:56 +05:30
rustc_hir_pretty pretty: fix to print some lifetimes on HIR pretty-print 2022-10-15 23:34:21 +09:00
rustc_hir_typeck Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_incremental Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_index Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_infer Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_interface Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_lexer rustc_lexer::TokenKind improve docs 2022-10-26 23:32:14 +02:00
rustc_lint Rollup merge of #103338 - l4l:enum-unreachable-pub, r=nagisa 2022-10-31 14:52:55 +05:30
rustc_lint_defs Rollup merge of #102635 - lcnr:incoherent_auto_trait_objects, r=jackh726 2022-10-22 00:13:59 +02:00
rustc_llvm llvm-16: Don't initialize removed legacy passes 2022-10-25 15:03:21 -07:00
rustc_log
rustc_macros Allow specifying multiple alternative suggestions 2022-10-23 18:59:13 +02:00
rustc_metadata Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_middle Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3 2022-11-01 14:12:25 +05:30
rustc_mir_build Rollup merge of #103584 - ouz-a:issue-102303, r=oli-obk 2022-11-01 14:12:25 +05:30
rustc_mir_dataflow Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_mir_transform Remove bounds check with enum cast 2022-10-31 14:10:37 +03:00
rustc_monomorphize Use tcx.require_lang_item 2022-10-29 16:09:15 -05:00
rustc_parse Rollup merge of #103544 - Nilstrieb:no-recovery-pls, r=compiler-errors 2022-10-27 15:03:58 +02:00
rustc_parse_format Detect and reject out-of-range integers in format string literals 2022-10-01 01:05:01 +02:00
rustc_passes Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
rustc_plugin_impl Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_privacy Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_query_impl Introduce UnordMap, UnordSet, and UnordBag (see MCP 533) 2022-10-27 13:23:26 +00:00
rustc_query_system Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_resolve Rollup merge of #103706 - zbyrn:issue-101637-fix, r=estebank 2022-11-01 14:12:26 +05:30
rustc_save_analysis Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_serialize remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
rustc_session Introduce dedicated -Zdylib-lto flag for enabling LTO on dylibs 2022-10-23 13:48:03 +02:00
rustc_smir Only keep one version of ImplicitSelfKind. 2022-09-13 19:18:23 +02:00
rustc_span Rollup merge of #97971 - Soveu:varargs, r=jackh726 2022-10-30 19:31:36 -07:00
rustc_symbol_mangling Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_target Rollup merge of #102689 - ayrtonm:master, r=cjgillot 2022-10-30 19:31:38 -07:00
rustc_trait_selection Rollup merge of #103603 - camsteffen:refactor-lang, r=oli-obk 2022-10-31 14:52:56 +05:30
rustc_traits rm try_normalize_mir_const_after_erasing_regions 2022-10-17 10:54:03 +02:00
rustc_transmute fix #103783, fix ICE checking transmutability of NaughtyLenArray 2022-10-30 06:21:27 +08:00
rustc_ty_utils Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_type_ir Deny const variables as well 2022-10-19 17:11:40 +00:00