Skip to content

Commit f2fd8e7

Browse files
committed
Auto merge of #3606 - detrumi:blacklisted_name_hashset, r=phansch
Use hashset in `blacklisted_name` lint
2 parents 6f39128 + d1dfd3e commit f2fd8e7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

clippy_lints/src/blacklisted_name.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::utils::span_lint;
1111
use rustc::hir::*;
1212
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1313
use rustc::{declare_tool_lint, lint_array};
14+
use rustc_data_structures::fx::FxHashSet;
1415

1516
/// **What it does:** Checks for usage of blacklisted names for variables, such
1617
/// as `foo`.
@@ -32,11 +33,11 @@ declare_clippy_lint! {
3233

3334
#[derive(Clone, Debug)]
3435
pub struct BlackListedName {
35-
blacklist: Vec<String>,
36+
blacklist: FxHashSet<String>,
3637
}
3738

3839
impl BlackListedName {
39-
pub fn new(blacklist: Vec<String>) -> Self {
40+
pub fn new(blacklist: FxHashSet<String>) -> Self {
4041
Self { blacklist }
4142
}
4243
}
@@ -50,7 +51,7 @@ impl LintPass for BlackListedName {
5051
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
5152
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
5253
if let PatKind::Binding(_, _, ident, _) = pat.node {
53-
if self.blacklist.iter().any(|s| ident.name == *s) {
54+
if self.blacklist.contains(&ident.name.to_string()) {
5455
span_lint(
5556
cx,
5657
BLACKLISTED_NAME,

clippy_lints/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
423423
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
424424
reg.register_late_lint_pass(box unused_label::UnusedLabel);
425425
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
426-
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
426+
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
427+
conf.blacklisted_names.iter().cloned().collect()
428+
));
427429
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
428430
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
429431
reg.register_late_lint_pass(box neg_multiply::NegMultiply);

0 commit comments

Comments
 (0)