-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add suggestions for misspelled method names #44297
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
I had some concerns when submitting this - not sure if this is the best approach.
|
If you want to integrate traits, to avoid issues like #43149 you want to
|
@arielb1 Thanks for the suggestion! I'll try to do that... |
r? @arielb1 -- you seem to be on top of this =) feel free to re-assign me though... |
Hi @laumann, just wanted to check in and make sure this is still on your radar! |
@aidanhs Hi, yes, it is, I'm sorry for the delay, but I've had little time to work on it, since submitting the PR. I was looking at it last night, implementing @arielb1's suggestions and I have it working to the point where the suggestions are found, they just need to be emitted. I got stuck at how to turn a Sorry again! |
You are supposed to have the |
And actually you don't want a |
a54f408
to
4a84be4
Compare
@arielb1 I've amended the commit and rebased it on top of master, but haven't yet run the tests. I'm really not sure if I've taken the right approach though :-/ It seems to be the right point to hook in, but I suspect that candidate assembly might include too many things that |
// Toggle the flag that allows for similar names to be found | ||
// and search again | ||
self.allow_similar_names = true; | ||
self.inherent_candidates.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be self.reset();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
let mut lev_candidates = Vec::with_capacity(self.inherent_candidates.len() + | ||
self.extension_candidates.len()); | ||
for lev_cand in self.inherent_candidates.iter().chain(self.extension_candidates.iter()) { | ||
lev_candidates.push(lev_cand.item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to try to pick each candidate, to avoid showing unusable candidates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to do this best. To pick, them I'd have to extract all the close matching names, run a probe
for each and call pick() ?
a3768c2
to
6fbf991
Compare
let mut pcx = ProbeContext::new(self.fcx, span, self.mode, self.method_name, | ||
self.return_type, vec![]); | ||
pcx.allow_similar_names = true; | ||
pcx.steps = steps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this might cause issues. The constructor for ProbeContext wants a Vec, but internally it's wrapped in an Rc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that shouldn't be a problem. maybe change the constructor to take an Rc for cleanness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
@arielb1 I think it's ready for review now. |
|
||
if !lev_candidates.is_empty() { | ||
use rustc_data_structures::fx::FxHashSet; | ||
let mut dedup = FxHashSet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this dedup
thing is redundant now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be - candidate_method_names
performs deduplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
@@ -799,7 +807,38 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { | |||
return Err(MethodError::PrivateMatch(def, out_of_scope_traits)); | |||
} | |||
|
|||
debug!("Probing for method names similar to {:?}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to extract this section to a separate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
68a6212
to
452524e
Compare
Should I do another rebase? |
Use the syntax::util::lev_distance module to provide suggestions when a named method cannot be found. Part of rust-lang#30197
452524e
to
09defbc
Compare
There's no need to - bors will automatically merge - but you can rebase if you want. It turns out that when working with levenshtein distance, we report the 1 best name that matches, as in: rust/src/librustc_typeck/check/mod.rs Lines 3038 to 3054 in e2504cf
|
24a0af8
to
8eff63f
Compare
@bors r+ |
📌 Commit 8eff63f has been approved by |
⌛ Testing commit 8eff63fdc12d153dd3301f0743a9f62204de64dd with merge a5c611a02164c07d86eccc2ddc99c4012aa5cffe... |
💔 Test failed - status-appveyor |
|
8eff63f
to
5d72356
Compare
test needs updating:
|
b2685dd
to
10098e2
Compare
@bors r+ |
📌 Commit 10098e2 has been approved by |
10098e2
to
4963394
Compare
The convention for suggesting close matches is to provide at most one match (the closest one). Change the suggestions for misspelt method names to obey that.
@bors r+ |
📌 Commit 4963394 has been approved by |
Add suggestions for misspelled method names Use the syntax::util::lev_distance module to provide suggestions when a named method cannot be found. Part of #30197
☀️ Test successful - status-appveyor, status-travis |
Use the syntax::util::lev_distance module to provide suggestions when a
named method cannot be found.
Part of #30197