Fix E0433 No Typo Suggestions#103706
Merged
bors merged 4 commits intorust-lang:masterfrom Nov 1, 2022
Merged
Conversation
Collaborator
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) soon. Please see the contribution instructions for more information. |
Contributor
Author
|
Oops, I don't know if people think there is too much text here. If so, please let me know I'll keep it short next time. |
Contributor
Author
|
cc @jackh726 since you were the reviewer in one of the previous PR's that worked on this |
Contributor
Author
|
@rustbot label T-compiler A-diagnostics |
Contributor
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Nov 1, 2022
Rollup of 6 pull requests Successful merges: - rust-lang#103061 (Rewrite implementation of `#[alloc_error_handler]`) - rust-lang#103584 (Remove bounds check when array is indexed by enum) - rust-lang#103706 (Fix E0433 No Typo Suggestions) - rust-lang#103729 (interpret: fix align_of_val on packed types) - rust-lang#103759 (Use `adt_def` during type collection.) - rust-lang#103809 (Fix a typo in std::net mod doc comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Structis not found, it isE0433: failed to resolve: use of undeclared type `Struct`.foois not found inStruct, it isE0599: no function or associated item named `foo` found for struct `Struct` in the current scopeWhen a name is used as a type,
e.g. fn foo() -> Struct, and the name cannot be resolved, it isE0412: cannot find type `Struct` in this scope.Before #72923,
E0433does not implement any suggestions, and the PR introduces suggestions for missinguses. 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::Structof a call tomodule::Struct::foo(). However, along with the suggestions, the smart-resolve function will reportE0412since 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 outE0412errors returned by the smart-resolve function with the realE0433error, but keeps the "missinguse" 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 aE0412messages, if there areusesuggestions, but says the normaluse of undeclared typeotherwise.Fixes
This fix swaps out all fields in
Diagnosticreturned by the smart-resolve function except forsuggestionswith the current error, and merges thesuggestionsof the returned error and that of the current error together. If there areusesuggestions, the error is saved touse_injectionto be reported at the end; otherwise, the error is emitted immediately asResolver::report_errordoes.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