Skip to content

improve similar method names suggestions #94747

Closed
@lovasoa

Description

@lovasoa

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 ;)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions