Skip to content

Commit 529f698

Browse files
committed
Auto merge of #3599 - xfix:use-hash-set-for-valid-idents, r=oli-obk
Use an FxHashSet for valid idents in documentation lint
2 parents 39bd844 + ab70e0e commit 529f698

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

clippy_lints/src/doc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use itertools::Itertools;
1212
use pulldown_cmark;
1313
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
1414
use rustc::{declare_tool_lint, lint_array};
15+
use rustc_data_structures::fx::FxHashSet;
1516
use syntax::ast;
1617
use syntax::source_map::{BytePos, Span};
1718
use syntax_pos::Pos;
@@ -43,11 +44,11 @@ declare_clippy_lint! {
4344

4445
#[derive(Clone)]
4546
pub struct Doc {
46-
valid_idents: Vec<String>,
47+
valid_idents: FxHashSet<String>,
4748
}
4849

4950
impl Doc {
50-
pub fn new(valid_idents: Vec<String>) -> Self {
51+
pub fn new(valid_idents: FxHashSet<String>) -> Self {
5152
Self { valid_idents }
5253
}
5354
}
@@ -144,7 +145,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
144145
panic!("not a doc-comment: {}", comment);
145146
}
146147

147-
pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'a [ast::Attribute]) {
148+
pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [ast::Attribute]) {
148149
let mut doc = String::new();
149150
let mut spans = vec![];
150151

@@ -192,7 +193,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'
192193

193194
fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
194195
cx: &EarlyContext<'_>,
195-
valid_idents: &[String],
196+
valid_idents: &FxHashSet<String>,
196197
docs: Events,
197198
spans: &[(usize, Span)],
198199
) {
@@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
237238
}
238239
}
239240

240-
fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) {
241+
fn check_text(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span) {
241242
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
242243
// Trim punctuation as in `some comment (see foo::bar).`
243244
// ^^
244245
// Or even as in `_foo bar_` which is emphasized.
245246
let word = word.trim_matches(|c: char| !c.is_alphanumeric());
246247

247-
if valid_idents.iter().any(|i| i == word) {
248+
if valid_idents.contains(word) {
248249
continue;
249250
}
250251

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
425425
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
426426
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
427427
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
428-
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone()));
428+
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
429429
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
430430
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
431431
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);

0 commit comments

Comments
 (0)