1
Fork 0

Rollup merge of #119819 - chenyukang:yukang-fix-118183-lint, r=davidtwco

Check rust lints when an unknown lint is detected

Fixes #118183
This commit is contained in:
Guillaume Gomez 2024-01-12 15:16:56 +01:00 committed by GitHub
commit 737452a824
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 19 deletions

View file

@ -170,6 +170,34 @@ pub fn find_best_match_for_name(
find_best_match_for_name_impl(false, candidates, lookup, dist)
}
/// 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.
pub fn find_best_match_for_names(
candidates: &[Symbol],
lookups: &[Symbol],
dist: Option<usize>,
) -> Option<Symbol> {
lookups
.iter()
.map(|s| (s, find_best_match_for_name_impl(false, candidates, *s, dist)))
.filter_map(|(s, r)| r.map(|r| (s, r)))
.min_by(|(s1, r1), (s2, r2)| {
let d1 = edit_distance(s1.as_str(), r1.as_str(), usize::MAX).unwrap();
let d2 = edit_distance(s2.as_str(), r2.as_str(), usize::MAX).unwrap();
d1.cmp(&d2)
})
.map(|(_, r)| r)
}
#[cold]
fn find_best_match_for_name_impl(
use_substring_score: bool,