diff options
| author | yukang <moorekang@gmail.com> | 2023-03-26 12:03:25 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2023-03-26 12:03:25 +0800 |
| commit | 7b4f436a30f00c8b8bf533b92592385cba2ea5f1 (patch) | |
| tree | f4ca5eb3b825218a18926782f45233c0ab0b3395 | |
| parent | a860a720baa508aa28d44f4d277814a086d6bd9d (diff) | |
| download | rust-7b4f436a30f00c8b8bf533b92592385cba2ea5f1.tar.gz rust-7b4f436a30f00c8b8bf533b92592385cba2ea5f1.zip | |
add comments and cleanup
| -rw-r--r-- | compiler/rustc_span/src/edit_distance.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/edit_distance.rs b/compiler/rustc_span/src/edit_distance.rs index 40d36578350..19c4aae97ef 100644 --- a/compiler/rustc_span/src/edit_distance.rs +++ b/compiler/rustc_span/src/edit_distance.rs @@ -190,6 +190,7 @@ fn find_best_match_for_name_impl( 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![]; for c in candidates { match if use_substring_score { @@ -200,19 +201,25 @@ fn find_best_match_for_name_impl( Some(0) => return Some(*c), Some(d) => { if use_substring_score { - dist = d; + if d < dist { + dist = d; + next_candidates.clear(); + } else { + // `d == dist` here, we need to store the candidates with the same distance + // so we won't decrease the distance in the next loop. + } next_candidates.push(*c); - best = Some(*c); } else { dist = d - 1; - best = Some(*c); } + best = Some(*c); } None => {} } } if next_candidates.len() > 1 { + debug_assert!(use_substring_score); best = find_best_match_for_name_impl( false, &next_candidates, |
