Skip to content

Commit 5e3df42

Browse files
committed
More advanced unknown lint suggestion
This copies the unknown_lints code clippy uses for its unknown_clippy_lints lint to rustc. The unknown_clippy_lints code is more advanced, because it doesn't suggest renamed or removed lints and correctly suggest lower casing lints.
1 parent c819a4c commit 5e3df42

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

compiler/rustc_lint/src/context.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,18 @@ impl LintStore {
412412
}
413413

414414
fn no_lint_suggestion(&self, lint_name: &str) -> CheckLintNameResult<'_> {
415-
let symbols = self.by_name.keys().map(|name| Symbol::intern(&name)).collect::<Vec<_>>();
415+
let name_lower = lint_name.to_lowercase();
416+
let symbols =
417+
self.get_lints().iter().map(|l| Symbol::intern(&l.name_lower())).collect::<Vec<_>>();
416418

417-
let suggestion =
418-
find_best_match_for_name(&symbols, Symbol::intern(&lint_name.to_lowercase()), None);
419-
420-
CheckLintNameResult::NoLint(suggestion)
419+
if lint_name.chars().any(char::is_uppercase) && self.find_lints(&name_lower).is_ok() {
420+
// First check if the lint name is (partly) in upper case instead of lower case...
421+
CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)))
422+
} else {
423+
// ...if not, search for lints with a similar name
424+
let suggestion = find_best_match_for_name(&symbols, Symbol::intern(&name_lower), None);
425+
CheckLintNameResult::NoLint(suggestion)
426+
}
421427
}
422428

423429
fn check_tool_name_for_backwards_compat(

0 commit comments

Comments
 (0)