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::utils::span_lint;
12 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13 use rustc::{declare_tool_lint, lint_array};
14 use rustc_data_structures::fx::FxHashSet;
16 /// **What it does:** Checks for usage of blacklisted names for variables, such
19 /// **Why is this bad?** These names are usually placeholder names and should be
22 /// **Known problems:** None.
28 declare_clippy_lint! {
31 "usage of a blacklisted/placeholder name"
34 #[derive(Clone, Debug)]
35 pub struct BlackListedName {
36 blacklist: FxHashSet<String>,
39 impl BlackListedName {
40 pub fn new(blacklist: FxHashSet<String>) -> Self {
45 impl LintPass for BlackListedName {
46 fn get_lints(&self) -> LintArray {
47 lint_array!(BLACKLISTED_NAME)
51 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
52 fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
53 if let PatKind::Binding(_, _, ident, _) = pat.node {
54 if self.blacklist.contains(&ident.name.to_string()) {
59 &format!("use of a blacklisted/placeholder name `{}`", ident.name),