diff options
| author | Martin Nordholts <martin.nordholts@codetale.se> | 2023-11-27 18:55:32 +0100 |
|---|---|---|
| committer | Martin Nordholts <martin.nordholts@codetale.se> | 2023-11-27 19:08:27 +0100 |
| commit | 45fc842ed93d206d3923b869eeb1437cd62e0be8 (patch) | |
| tree | 1f975df94d3292869c0fe2aa3502b66c167b376a /compiler/rustc_span/src | |
| parent | aa330518f47f26c627448832e2cae0a00c57a475 (diff) | |
| download | rust-45fc842ed93d206d3923b869eeb1437cd62e0be8.tar.gz rust-45fc842ed93d206d3923b869eeb1437cd62e0be8.zip | |
rustc_span: Use correct edit distance start length for suggestions
Otherwise the suggestions can be off-base for non-ASCII identifiers. For example suggesting that `Ok` is a name similar to `读文`.
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/edit_distance.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/edit_distance.rs b/compiler/rustc_span/src/edit_distance.rs index 96a118e590f..14cb1d6d362 100644 --- a/compiler/rustc_span/src/edit_distance.rs +++ b/compiler/rustc_span/src/edit_distance.rs @@ -188,7 +188,11 @@ fn find_best_match_for_name_impl( return Some(*c); } - let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3); + // `fn edit_distance()` use `chars()` to calculate edit distance, so we must + // also use `chars()` (and not `str::len()`) to calculate length here. + let lookup_len = lookup.chars().count(); + + let mut dist = dist.unwrap_or_else(|| cmp::max(lookup_len, 3) / 3); let mut best = None; // store the candidates with the same distance, only for `use_substring_score` current. let mut next_candidates = vec![]; |
