rustc_span::edit_distance

Function find_best_match_for_names

Source
pub fn find_best_match_for_names(
    candidates: &[Symbol],
    lookups: &[Symbol],
    dist: Option<usize>,
) -> Option<Symbol>
Expand description

Find the best match for multiple words

This function is intended for use when the desired match would never be returned due to a substring in lookup which is superfluous.

For example, when looking for the closest lint name to clippy:missing_docs, we would find clippy::erasing_op, despite missing_docs existing and being a better suggestion. missing_docs would have a larger edit distance because it does not contain the clippy tool prefix. In order to find missing_docs, this function takes multiple lookup strings, computes the best match for each and returns the match which had the lowest edit distance. In our example, clippy:missing_docs and missing_docs would be lookups, enabling missing_docs to be the best match, as desired.