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

improve similar method names suggestions #94747

Closed
lovasoa opened this issue Mar 8, 2022 · 1 comment · Fixed by #95119
Closed

improve similar method names suggestions #94747

lovasoa opened this issue Mar 8, 2022 · 1 comment · Fixed by #95119
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lovasoa
Copy link
Contributor

lovasoa commented Mar 8, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af286f54d571ef5e00cd728ea244b3aa

fn main() {
    vec![].bs_xmpty();
    vec![].empty();
}

The current output is:

error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `bs_xmpty` found for struct `Vec<_>` in the current scope
 [--> src/main.rs:2:12
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af286f54d571ef5e00cd728ea244b3aa#)  |
2 |     vec![].bs_xmpty();
  |            ^^^^^^^^ help: there is an associated function with a similar name: `is_empty`

error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `empty` found for struct `Vec<_>` in the current scope
 [--> src/main.rs:3:12
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af286f54d571ef5e00cd728ea244b3aa#)  |
3 |     vec![].empty();
  |            ^^^^^ method not found in `Vec<_>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to 2 previous errors

Ideally the output should look like:

error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `bs_xmpty` found for struct `Vec<_>` in the current scope
 [--> src/main.rs:2:12
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af286f54d571ef5e00cd728ea244b3aa#)  |
2 |     vec![].bs_xmpty();
  |            ^^^^^^^^ help: there is an associated function with a similar name: `is_empty`

error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `empty` found for struct `Vec<_>` in the current scope
 [--> src/main.rs:3:12
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af286f54d571ef5e00cd728ea244b3aa#)  |
3 |     vec![].empty();
  |            ^^^^^^^^ help: there is an associated function with a similar name: `is_empty`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to 2 previous errors

To a human, the method name is_empty is much closer to empty than to bs_xmpty.
However, the algorithm used by the compiler to suggest similar method names seems a little bit simplistic and fails to suggest anything when a naive programmer like me types empty() instead of is_empty. The programmer then has to open the documentation, and he does not like that ;)

@lovasoa lovasoa 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 Mar 8, 2022
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Mar 9, 2022
@OliverMD
Copy link
Contributor

@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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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.

3 participants