mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Use hashset for name blacklist
This commit is contained in:
parent
529f698c23
commit
d1dfd3e96f
2 changed files with 7 additions and 4 deletions
|
@ -11,6 +11,7 @@ use crate::utils::span_lint;
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_tool_lint, lint_array};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
|
||||
/// **What it does:** Checks for usage of blacklisted names for variables, such
|
||||
/// as `foo`.
|
||||
|
@ -32,11 +33,11 @@ declare_clippy_lint! {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BlackListedName {
|
||||
blacklist: Vec<String>,
|
||||
blacklist: FxHashSet<String>,
|
||||
}
|
||||
|
||||
impl BlackListedName {
|
||||
pub fn new(blacklist: Vec<String>) -> Self {
|
||||
pub fn new(blacklist: FxHashSet<String>) -> Self {
|
||||
Self { blacklist }
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +51,7 @@ impl LintPass for BlackListedName {
|
|||
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) {
|
||||
if self.blacklist.contains(&ident.name.to_string()) {
|
||||
span_lint(
|
||||
cx,
|
||||
BLACKLISTED_NAME,
|
||||
|
|
|
@ -423,7 +423,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
|||
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
|
||||
reg.register_late_lint_pass(box unused_label::UnusedLabel);
|
||||
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
|
||||
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
|
||||
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
|
||||
conf.blacklisted_names.iter().cloned().collect()
|
||||
));
|
||||
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
|
||||
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
|
||||
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
|
||||
|
|
Loading…
Reference in a new issue