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

Suggest similar names for types, macros and modules #96625

Closed
Zoybean opened this issue May 2, 2022 · 2 comments · Fixed by #103706
Closed

Suggest similar names for types, macros and modules #96625

Zoybean opened this issue May 2, 2022 · 2 comments · Fixed by #103706
Assignees
Labels
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.

Comments

@Zoybean
Copy link

Zoybean commented May 2, 2022

Given the following code: Playground link

fn main() {
    let s = string::new();
    let s = Str::new();
}

The current output is:

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

error[E0433]: failed to resolve: use of undeclared type `Str`
 --> src/main.rs:3:13
  |
3 |     let s = Str::new();
  |             ^^^ use of undeclared type `Str`

Some errors have detailed explanations: E0433.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `sandbox` due to 2 previous errors

Ideally the output should look like:

error[E0433]: failed to resolve: use of undeclared crate or module `string`
 --> src/main.rs:2:13
  |
2 |     let s = string::new();
  |             ^^^^^^ use of undeclared crate or module `string`
  |
help: there is a type with a similar name (notice the capitalization)
  |
2 |     let s = String::new();
  |             ~~~~~~
help: there is a type with a similar name
  |
3 |     let s = str::new();
  |             ~~~

error[E0433]: failed to resolve: use of undeclared type `Str`
 --> src/main.rs:3:13
  |
3 |     let s = Str::new();
  |             ^^^ use of undeclared type `Str`
help: there is a type with a similar name (notice the capitalization)
  |
3 |     let s = str::new();
  |             ~~~
help: there is a type with a similar name
  |
2 |     let s = String::new();
  |             ~~~~~~

Some errors have detailed explanations: E0433.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `sandbox` due to 2 previous errors

Currently, when a crate, function, method, or enum variant is not found, similar-named items will be shown as hints. However, when a type, module, or macro is misspelled, the same kind of hints are not shown. I particularly think mistakes involving capitalisation should be considered. This issue came about with a friend I was introducing to rust, and I was hoping the compiler would suggest correcting string to String.

@Zoybean Zoybean 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. labels May 2, 2022
@Zoybean
Copy link
Author

Zoybean commented May 2, 2022

Potentially related issues: #95462, #48676

@m-ysk
Copy link
Contributor

m-ysk commented May 6, 2022

@rustbot claim

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 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.

2 participants