From d1dfd3e96f4b4ffd928501e6f253dee3c166c2c5 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Mon, 31 Dec 2018 10:44:27 +0100 Subject: [PATCH] Use hashset for name blacklist --- clippy_lints/src/blacklisted_name.rs | 7 ++++--- clippy_lints/src/lib.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index ce7da4194971..ed7437e495b9 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, + blacklist: FxHashSet, } impl BlackListedName { - pub fn new(blacklist: Vec) -> Self { + pub fn new(blacklist: FxHashSet) -> 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 fb5a29dbd34e..2e515cc8aea6 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);