Skip to content

Commit 8e3a6f4

Browse files
Update compiler/rustc_span/src/edit_distance.rs
Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
1 parent 927cbe2 commit 8e3a6f4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

compiler/rustc_span/src/edit_distance.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,20 @@ pub fn find_best_match_for_name(
170170
find_best_match_for_name_impl(false, candidates, lookup, dist)
171171
}
172172

173-
/// Find the best match for a give word list
173+
/// Find the best match for multiple words
174174
///
175-
/// This function is helpfull when we have multiple patterns for candidates, for example:
175+
/// This function is intended for use when the desired match would never be
176+
/// returned due to a substring in `lookup` which is superfluous.
176177
///
177-
/// For give keyword `clippy::missing_docs`, we may have multiple candidates:
178-
/// - `clippy::missing_docs_in_private_items`
179-
/// - `clippy::erasing_op`
180-
/// - `missing_docs`
181-
///
182-
/// We want to find the best match for the given keyword, strip a prefix to get `missing_docs`,
183-
/// then call this function with `lookups` as `["clippy::missing_docs", "missing_docs"]`
178+
/// For example, when looking for the closest lint name to
179+
/// `clippy:missing_docs`, we would find `clippy::erasing_op`, despite
180+
/// `missing_docs` existing and being a better suggestion. `missing_docs`
181+
/// would have a larger edit distance because it does not contain the
182+
/// `clippy` tool prefix. In order to find `missing_docs`, this function
183+
/// takes multiple lookup strings, computes the best match for each and
184+
/// returns the match which had the lowest edit distance. In our example,
185+
/// clippy:missing_docs` and `missing_docs` would be `lookups`, enabling
186+
/// `missing_docs` to be the best match, as desired.
184187
pub fn find_best_match_for_names(
185188
candidates: &[Symbol],
186189
lookups: &[Symbol],

0 commit comments

Comments
 (0)