]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/blacklisted_name.rs
Auto merge of #4809 - iankronquist:patch-1, r=flip1995
[rust.git] / clippy_lints / src / blacklisted_name.rs
index e5af07890644ff83b4e6741730eec4eb3da6fba9..cb68ba598868eded5ca2896ceab190d6033341b9 100644 (file)
@@ -1,49 +1,44 @@
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_lint, lint_array};
-use rustc::hir::*;
 use crate::utils::span_lint;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_hir::*;
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
 
-/// **What it does:** Checks for usage of blacklisted names for variables, such
-/// as `foo`.
-///
-/// **Why is this bad?** These names are usually placeholder names and should be
-/// avoided.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// let foo = 3.14;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for usage of blacklisted names for variables, such
+    /// as `foo`.
+    ///
+    /// **Why is this bad?** These names are usually placeholder names and should be
+    /// avoided.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let foo = 3.14;
+    /// ```
     pub BLACKLISTED_NAME,
     style,
     "usage of a blacklisted/placeholder name"
 }
 
 #[derive(Clone, Debug)]
-pub struct BlackListedName {
-    blacklist: Vec<String>,
+pub struct BlacklistedName {
+    blacklist: FxHashSet<String>,
 }
 
-impl BlackListedName {
-    pub fn new(blacklist: Vec<String>) -> Self {
-        Self {
-            blacklist,
-        }
+impl BlacklistedName {
+    pub fn new(blacklist: FxHashSet<String>) -> Self {
+        Self { blacklist }
     }
 }
 
-impl LintPass for BlackListedName {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(BLACKLISTED_NAME)
-    }
-}
+impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
 
-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) {
+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.kind {
+            if self.blacklist.contains(&ident.name.to_string()) {
                 span_lint(
                     cx,
                     BLACKLISTED_NAME,