]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/blacklisted_name.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / blacklisted_name.rs
index ce7adda092cdf0458995d7c7a84b1bf712451bea..c1ee4d528854609648067f967a03892e511ab06d 100644 (file)
@@ -1,33 +1,35 @@
-use rustc::lint::*;
+use crate::utils::span_lint;
 use rustc::hir::*;
-use utils::span_lint;
+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`.
-///
-/// **Why is this bad?** These names are usually placeholder names and should be
-/// avoided.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// let foo = 3.14;
-/// ```
-declare_lint! {
+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,
-    Warn,
+    style,
     "usage of a blacklisted/placeholder name"
 }
 
 #[derive(Clone, Debug)]
 pub struct BlackListedName {
-    blacklist: Vec<String>,
+    blacklist: FxHashSet<String>,
 }
 
 impl BlackListedName {
-    pub fn new(blacklist: Vec<String>) -> BlackListedName {
-        BlackListedName { blacklist: blacklist }
+    pub fn new(blacklist: FxHashSet<String>) -> Self {
+        Self { blacklist }
     }
 }
 
@@ -35,16 +37,21 @@ impl LintPass for BlackListedName {
     fn get_lints(&self) -> LintArray {
         lint_array!(BLACKLISTED_NAME)
     }
+    fn name(&self) -> &'static str {
+        "BlacklistedName"
+    }
 }
 
-impl LateLintPass for BlackListedName {
-    fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
-        if let PatKind::Binding(_, _, ref ident, _) = pat.node {
-            if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
-                span_lint(cx,
-                          BLACKLISTED_NAME,
-                          pat.span,
-                          &format!("use of a blacklisted/placeholder name `{}`", ident.node));
+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.contains(&ident.name.to_string()) {
+                span_lint(
+                    cx,
+                    BLACKLISTED_NAME,
+                    ident.span,
+                    &format!("use of a blacklisted/placeholder name `{}`", ident.name),
+                );
             }
         }
     }