X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fblacklisted_name.rs;h=29660399233038f7f33fb3bfcd9639329b2c04d4;hb=48cb6e273ea49e85b6baa209e0123a2bbd6d15c2;hp=5cb84f62651b29d042e6a306268fc5259a97a80e;hpb=9110b6eb601ff45dcf31e9ed58fa4d93a3b24220;p=rust.git diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 5cb84f62651..29660399233 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -1,17 +1,22 @@ use rustc::lint::*; use rustc::hir::*; -use utils::span_lint; +use crate::utils::span_lint; -/// **What it does:** This lints about usage of blacklisted names. +/// **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. +/// **Why is this bad?** These names are usually placeholder names and should be +/// avoided. /// /// **Known problems:** None. /// -/// **Example:** `let foo = 3.14;` -declare_lint! { +/// **Example:** +/// ```rust +/// let foo = 3.14; +/// ``` +declare_clippy_lint! { pub BLACKLISTED_NAME, - Warn, + style, "usage of a blacklisted/placeholder name" } @@ -21,8 +26,10 @@ pub struct BlackListedName { } impl BlackListedName { - pub fn new(blacklist: Vec) -> BlackListedName { - BlackListedName { blacklist: blacklist } + pub fn new(blacklist: Vec) -> Self { + Self { + blacklist, + } } } @@ -32,14 +39,16 @@ fn get_lints(&self) -> LintArray { } } -impl LateLintPass for BlackListedName { - fn check_pat(&mut self, cx: &LateContext, pat: &Pat) { - if let PatKind::Ident(_, 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.iter().any(|s| ident.name == *s) { + span_lint( + cx, + BLACKLISTED_NAME, + ident.span, + &format!("use of a blacklisted/placeholder name `{}`", ident.name), + ); } } }