diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-01-20 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-01-26 12:38:22 +0100 |
| commit | 6236882127eb2a9213a58bf431399727a6c3505d (patch) | |
| tree | e1a1136f3711b36a491aa852df0743009a40b30b /compiler/rustc_parse | |
| parent | 380d53fb2c2190204b977a86ffc9fe74c083af5c (diff) | |
| download | rust-6236882127eb2a9213a58bf431399727a6c3505d.tar.gz rust-6236882127eb2a9213a58bf431399727a6c3505d.zip | |
Introduce a limit to Levenshtein distance computation
Incorporate distance limit from `find_best_match_for_name` directly into Levenshtein distance computation. Use the string size difference as a lower bound on the distance and exit early when it exceeds the specified limit. After finding a candidate within a limit, lower the limit further to restrict the search space.
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index ade441b0e7d..06849b31256 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -423,7 +423,7 @@ impl<'a> Parser<'a> { // Maybe the user misspelled `macro_rules` (issue #91227) if self.token.is_ident() && path.segments.len() == 1 - && lev_distance("macro_rules", &path.segments[0].ident.to_string()) <= 3 + && lev_distance("macro_rules", &path.segments[0].ident.to_string(), 3).is_some() { err.span_suggestion( path.span, |
