about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2021-01-16 17:11:26 +0100
committerflip1995 <hello@philkrones.com>2021-01-16 19:44:46 +0100
commit5e3df4266aa31a688ac0909a0a7845bca7e563c0 (patch)
treee544b871cd01065a8afd0633cea6f75d57ec00ff
parentc819a4c0255fc8857ebadb74763edd9b9f9c9601 (diff)
downloadrust-5e3df4266aa31a688ac0909a0a7845bca7e563c0.tar.gz
rust-5e3df4266aa31a688ac0909a0a7845bca7e563c0.zip
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.
-rw-r--r--compiler/rustc_lint/src/context.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index c4df0acbbb0..3971a309982 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -412,12 +412,18 @@ impl LintStore {
     }
 
     fn no_lint_suggestion(&self, lint_name: &str) -> CheckLintNameResult<'_> {
-        let symbols = self.by_name.keys().map(|name| Symbol::intern(&name)).collect::<Vec<_>>();
+        let name_lower = lint_name.to_lowercase();
+        let symbols =
+            self.get_lints().iter().map(|l| Symbol::intern(&l.name_lower())).collect::<Vec<_>>();
 
-        let suggestion =
-            find_best_match_for_name(&symbols, Symbol::intern(&lint_name.to_lowercase()), None);
-
-        CheckLintNameResult::NoLint(suggestion)
+        if lint_name.chars().any(char::is_uppercase) && self.find_lints(&name_lower).is_ok() {
+            // First check if the lint name is (partly) in upper case instead of lower case...
+            CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)))
+        } else {
+            // ...if not, search for lints with a similar name
+            let suggestion = find_best_match_for_name(&symbols, Symbol::intern(&name_lower), None);
+            CheckLintNameResult::NoLint(suggestion)
+        }
     }
 
     fn check_tool_name_for_backwards_compat(