diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 024907185e9..a3504e7e330 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -12,6 +12,7 @@ use itertools::Itertools; use pulldown_cmark; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, lint_array}; +use rustc_data_structures::fx::FxHashSet; use syntax::ast; use syntax::source_map::{BytePos, Span}; use syntax_pos::Pos; @@ -43,11 +44,11 @@ declare_clippy_lint! { #[derive(Clone)] pub struct Doc { - valid_idents: Vec, + valid_idents: FxHashSet, } impl Doc { - pub fn new(valid_idents: Vec) -> Self { + pub fn new(valid_idents: FxHashSet) -> Self { Self { valid_idents } } } @@ -144,7 +145,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<( panic!("not a doc-comment: {}", comment); } -pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'a [ast::Attribute]) { +pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &FxHashSet, attrs: &'a [ast::Attribute]) { let mut doc = String::new(); let mut spans = vec![]; @@ -192,7 +193,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &' fn check_doc<'a, Events: Iterator)>>( cx: &EarlyContext<'_>, - valid_idents: &[String], + valid_idents: &FxHashSet, docs: Events, spans: &[(usize, Span)], ) { @@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator)>>( } } -fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) { +fn check_text(cx: &EarlyContext<'_>, valid_idents: &FxHashSet, text: &str, span: Span) { for word in text.split(|c: char| c.is_whitespace() || c == '\'') { // Trim punctuation as in `some comment (see foo::bar).` // ^^ // Or even as in `_foo bar_` which is emphasized. let word = word.trim_matches(|c: char| !c.is_alphanumeric()); - if valid_idents.iter().any(|i| i == word) { + if valid_idents.contains(word) { continue; } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 27905b91750..fb5a29dbd34 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -425,7 +425,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { 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 functions::Functions::new(conf.too_many_arguments_threshold)); - reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone())); + 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); reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval); reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);