1 use crate::utils::span_lint;
2 use rustc_data_structures::fx::FxHashSet;
3 use rustc_hir::{Pat, PatKind};
4 use rustc_lint::{LateContext, LateLintPass};
5 use rustc_session::{declare_tool_lint, impl_lint_pass};
8 /// **What it does:** Checks for usage of blacklisted names for variables, such
11 /// **Why is this bad?** These names are usually placeholder names and should be
14 /// **Known problems:** None.
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_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
38 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
39 fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
40 if let PatKind::Binding(.., ident, _) = pat.kind {
41 if self.blacklist.contains(&ident.name.to_string()) {
46 &format!("use of a blacklisted/placeholder name `{}`", ident.name),