Skip to content

Targeted suggestions for specific "no method" errors on standard library types #59450

Closed
@dtolnay

Description

@dtolnay

Rustc currently shows a perfectly reasonable error message when calling a nonexistent method:

use std::collections::BTreeSet;

fn main() {
    let mut set = BTreeSet::new();
    set.push("");
}
error[E0599]: no method named `push` found for type `std::collections::BTreeSet<_>` in the current scope
 --> src/main.rs:5:9
  |
5 |     set.push("");
  |         ^^^^

But for specific frequently encountered cases, it would be great to show a more targeted error that gives the name of the method you almost definitely meant to call, despite not being similar enough to trigger the "did you mean" suggestion.

Candidates would be cases that arise often from refactoring (this applies to BTreeSet::push, which I see every now and then after replacing a Vec with a BTreeSet) or cases of a Rust API being named differently from an equivalent C++ API.

  • BTreeSet::push ⟶ suggest insert
  • Vec::push_back ⟶ suggest push
  • VecDeque::push ⟶ suggest push_back
  • Vec::length, Vec::size ⟶ suggest len

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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