about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonrad Borowski <konrad@borowski.pw>2018-12-29 18:07:10 +0100
committerKonrad Borowski <konrad@borowski.pw>2018-12-29 18:08:53 +0100
commitab70e0e7422ef3f53f5357ea99a739cbcbe6caee (patch)
treeda756ae4c937df81df53ebfc061e66386ec3230e
parent4d60841205d10293d6759df1948acda4c607c7eb (diff)
downloadrust-ab70e0e7422ef3f53f5357ea99a739cbcbe6caee.tar.gz
rust-ab70e0e7422ef3f53f5357ea99a739cbcbe6caee.zip
Use an FxHashSet for valid idents in documentation lint
-rw-r--r--clippy_lints/src/doc.rs13
-rw-r--r--clippy_lints/src/lib.rs2
2 files changed, 8 insertions, 7 deletions
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<String>,
+    valid_idents: FxHashSet<String>,
 }
 
 impl Doc {
-    pub fn new(valid_idents: Vec<String>) -> Self {
+    pub fn new(valid_idents: FxHashSet<String>) -> 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<String>, 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<Item = (usize, pulldown_cmark::Event<'a>)>>(
     cx: &EarlyContext<'_>,
-    valid_idents: &[String],
+    valid_idents: &FxHashSet<String>,
     docs: Events,
     spans: &[(usize, Span)],
 ) {
@@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
     }
 }
 
-fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) {
+fn check_text(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, 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 96af1642e8a..cfa99b0b75a 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);