about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilco Kusee <wilcokusee@gmail.com>2018-12-31 10:44:27 +0100
committerWilco Kusee <wilcokusee@gmail.com>2018-12-31 10:44:27 +0100
commitd1dfd3e96f4b4ffd928501e6f253dee3c166c2c5 (patch)
tree0c6bf91075c0b55a9fe8580485d299e9556c446b
parent529f698c23099cbdb0afe5fe308814639808233d (diff)
downloadrust-d1dfd3e96f4b4ffd928501e6f253dee3c166c2c5.tar.gz
rust-d1dfd3e96f4b4ffd928501e6f253dee3c166c2c5.zip
Use hashset for name blacklist
-rw-r--r--clippy_lints/src/blacklisted_name.rs7
-rw-r--r--clippy_lints/src/lib.rs4
2 files changed, 7 insertions, 4 deletions
diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs
index ce7da419497..ed7437e495b 100644
--- a/clippy_lints/src/blacklisted_name.rs
+++ b/clippy_lints/src/blacklisted_name.rs
@@ -11,6 +11,7 @@ use crate::utils::span_lint;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::{declare_tool_lint, lint_array};
+use rustc_data_structures::fx::FxHashSet;
 
 /// **What it does:** Checks for usage of blacklisted names for variables, such
 /// as `foo`.
@@ -32,11 +33,11 @@ declare_clippy_lint! {
 
 #[derive(Clone, Debug)]
 pub struct BlackListedName {
-    blacklist: Vec<String>,
+    blacklist: FxHashSet<String>,
 }
 
 impl BlackListedName {
-    pub fn new(blacklist: Vec<String>) -> Self {
+    pub fn new(blacklist: FxHashSet<String>) -> Self {
         Self { blacklist }
     }
 }
@@ -50,7 +51,7 @@ impl LintPass for BlackListedName {
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
     fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
         if let PatKind::Binding(_, _, ident, _) = pat.node {
-            if self.blacklist.iter().any(|s| ident.name == *s) {
+            if self.blacklist.contains(&ident.name.to_string()) {
                 span_lint(
                     cx,
                     BLACKLISTED_NAME,
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index fb5a29dbd34..2e515cc8aea 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -423,7 +423,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
     reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
     reg.register_late_lint_pass(box unused_label::UnusedLabel);
     reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
-    reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
+    reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
+            conf.blacklisted_names.iter().cloned().collect()
+    ));
     reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
     reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
     reg.register_late_lint_pass(box neg_multiply::NegMultiply);