Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0433 should do fuzzy matching to look for types that would be valid #87791

Closed
estebank opened this issue Aug 5, 2021 · 7 comments · Fixed by #103706
Closed

E0433 should do fuzzy matching to look for types that would be valid #87791

estebank opened this issue Aug 5, 2021 · 7 comments · Fixed by #103706
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Aug 5, 2021

The following code

    let _ = string::new();

produces:

error[E0433]: failed to resolve: use of undeclared crate or module `string`
 --> src/main.rs:2:13
  |
2 |     let _ = string::new();
  |             ^^^^^^ use of undeclared crate or module `string`

We should be doing fuzzy matching like we do in other cases and suggest changing string to String.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-papercut Diagnostics: An error or lint that needs small tweaks. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Aug 5, 2021
@inquisitivecrystal inquisitivecrystal added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 6, 2021
@camelid camelid added the A-resolve Area: Path resolution label Aug 21, 2021
@ptrojahn
Copy link
Contributor

@rustbot claim

@ptrojahn ptrojahn removed their assignment May 17, 2022
@Milo123459
Copy link
Contributor

@rustbot claim

Before I start working on this, I have some quick questions: what is the input for the fuzzy matching? It needs to have a list of all types, structs that are available in the file (or not!) and also std ones. I'm just not entirely sure how to go about doing this.

PS: I'm pretty sure this is going to require adding some sort of crate to rustc, is that okay?

@estebank
Copy link
Contributor Author

I don't think adding something will be needed. rustc_resolve already has some facilities in place to search for "all items" and then we have a levenshtein distance function that can let us linearly scan all type names for ones that have a short distance.

@Milo123459
Copy link
Contributor

I've been searching through the code for a bit, and I'm yet to find a function that can search for "all items", and the leven function?

@estebank
Copy link
Contributor Author

@Milo123459 I am pretty sure there's such a function. I'm looking at https://github.com/rust-lang/rust/blob/3e5800b8d30fba923c5070ae660c1e45a630a191/compiler/rustc_resolve/src/late/diagnostics.rs, which is where would expect it to be used at least once.

@Milo123459
Copy link
Contributor

Okay, I think I have an idea of how to implement this - I need a Namespace for the entire project and std library.. I think?

@estebank
Copy link
Contributor Author

Namespace only differentiates between the kind of items that can be referenced, not their scope. By that I mean it lets you say "I want all the names that are types, not variables", for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants