-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add case insensitive comparison, besides Levenstein for DYM #46347
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3212,6 +3212,18 @@ impl<'a> Resolver<'a> { | |
let name = path[path.len() - 1].node.name; | ||
// Make sure error reporting is deterministic. | ||
names.sort_by_key(|name| name.as_str()); | ||
|
||
|
||
// Ugly code, just to see if using case insensitive comparison will help | ||
let exact_match = names.iter().find(|x| x.as_str().to_uppercase() == name.as_str().to_uppercase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the following to account for @petrochenkov's comment names.iter().find(|x| {
x.as_str().to_uppercase() == name.as_str().to_uppercase() && x.as_str() != name.as_str()
}) |
||
// do not use Levenstein, just return the value we found (if any) | ||
if exact_match.is_some() { | ||
return match exact_match { | ||
Some(found) => Some(found.clone()), | ||
_ => None, | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Less nesting: if case_insensitive_match.is_some() {
return case_insensitive_match.cloned()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code can be written as if let Some(found) = exact_match {
return Some(found.clone());
} |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It occurs to me that we should likely be making this change as a "tiebreaker" in |
||
match find_best_match_for_name(names.iter(), &name.as_str(), None) { | ||
Some(found) if found != name => Some(found), | ||
_ => None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Original problem is Levenstein distance. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fn TyUint() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (An enum variant rather than a function is closer to the spirit of the example in the issue (which isn't to say that we shouldn't test functions, too, but those are |
||
println!("TyUint"); | ||
} | ||
|
||
fn TyInt() { | ||
println!("TyInt"); | ||
} | ||
|
||
|
||
fn main() { | ||
TyUInt(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're missing the |
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.
case_insensitive_match
would be a less-misleading name.