1 use crate::utils::span_lint;
3 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4 use rustc::{declare_tool_lint, lint_array};
5 use rustc_data_structures::fx::FxHashSet;
7 /// **What it does:** Checks for usage of blacklisted names for variables, such
10 /// **Why is this bad?** These names are usually placeholder names and should be
13 /// **Known problems:** None.
19 declare_clippy_lint! {
22 "usage of a blacklisted/placeholder name"
25 #[derive(Clone, Debug)]
26 pub struct BlackListedName {
27 blacklist: FxHashSet<String>,
30 impl BlackListedName {
31 pub fn new(blacklist: FxHashSet<String>) -> Self {
36 impl LintPass for BlackListedName {
37 fn get_lints(&self) -> LintArray {
38 lint_array!(BLACKLISTED_NAME)
40 fn name(&self) -> &'static str {
45 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
46 fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
47 if let PatKind::Binding(.., ident, _) = pat.node {
48 if self.blacklist.contains(&ident.name.to_string()) {
53 &format!("use of a blacklisted/placeholder name `{}`", ident.name),