You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Targeted suggestions for specific "no method" errors on standard library types #59450
Rustc currently shows a perfectly reasonable error message when calling a nonexistent method:
use std::collections::BTreeSet;fnmain(){letmut 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.
error[E0599]: no method named `push` found for type `std::collections::BTreeSet<_>` in the current scope
--> src/main.rs:5:9
|
5 | set.push("");
| ^^^^ help: you might have meant to use `insert`
Something similar to rustc_on_unimplemented sounds like it would work! I don't know enough about the diagnostics implementation to know what the other options are.
Bonus points if it is straightforward for a new rustc contributor to add a confusable and corresponding test case.
Activity
estebank commentedon Mar 27, 2019
Do you think this would be a common enough pattern that it'd be worth creating something like
rustc_on_unimplementedbut for confusables?Something like
dtolnay commentedon Mar 27, 2019
Something similar to rustc_on_unimplemented sounds like it would work! I don't know enough about the diagnostics implementation to know what the other options are.
Bonus points if it is straightforward for a new rustc contributor to add a confusable and corresponding test case.
fmease commentedon Oct 19, 2022
We could also reuse (abuse?)
#[doc(alias = "…")]for this. I think I've seen this mentioned a few times.kadiwa4 commentedon Jan 23, 2023
Maybe relevant: #107108 adds
doc(alias)support to that errorjieyouxu commentedon Feb 1, 2024
Now that PR #112239 is merged, it should be easy to add
#[rustc_confusables(...)]to some of these methods along with some tests.Add `rustc_confusables` annotations to some stdlib APIs
Add `rustc_confusables` annotations to some stdlib APIs
Add `rustc_confusables` annotations to some stdlib APIs
Add `rustc_confusables` annotations to some stdlib APIs
estebank commentedon Feb 14, 2024
I'll have #120730 close this ticket. We can open new ones for specific methods that require more aliases.
Rollup merge of rust-lang#120730 - estebank:confusable-api, r=oli-obk
Auto merge of rust-lang#120730 - estebank:confusable-api, r=oli-obk
Add `rustc_confusables` annotations to some stdlib APIs
Auto merge of rust-lang#120730 - estebank:confusable-api, r=oli-obk