1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use crate::rustc::hir::*;
11 use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12 use crate::rustc::{declare_tool_lint, lint_array};
13 use crate::utils::span_lint;
15 /// **What it does:** Checks for usage of blacklisted names for variables, such
18 /// **Why is this bad?** These names are usually placeholder names and should be
21 /// **Known problems:** None.
27 declare_clippy_lint! {
30 "usage of a blacklisted/placeholder name"
33 #[derive(Clone, Debug)]
34 pub struct BlackListedName {
35 blacklist: Vec<String>,
38 impl BlackListedName {
39 pub fn new(blacklist: Vec<String>) -> Self {
44 impl LintPass for BlackListedName {
45 fn get_lints(&self) -> LintArray {
46 lint_array!(BLACKLISTED_NAME)
50 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
51 fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
52 if let PatKind::Binding(_, _, ident, _) = pat.node {
53 if self.blacklist.iter().any(|s| ident.name == *s) {
58 &format!("use of a blacklisted/placeholder name `{}`", ident.name),