Closed
Description
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
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.