summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span/src/edit_distance.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
commit73e0a5b7696ea019ba35b89f38fc8e7b285d99cb (patch)
tree0d2e175af6f114cb50a675bec0bc76e12e1bceb4 /compiler/rustc_span/src/edit_distance.rs
parentAdding upstream version 1.75.0+dfsg1. (diff)
downloadrustc-upstream.tar.xz
rustc-upstream.zip
Adding upstream version 1.76.0+dfsg1.upstream/1.76.0+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_span/src/edit_distance.rs')
-rw-r--r--compiler/rustc_span/src/edit_distance.rs6
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 96a118e59..14cb1d6d3 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![];