Use an FxHashSet for valid idents in documentation lint
This commit is contained in:
@@ -12,6 +12,7 @@ use itertools::Itertools;
|
|||||||
use pulldown_cmark;
|
use pulldown_cmark;
|
||||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_tool_lint, lint_array};
|
use rustc::{declare_tool_lint, lint_array};
|
||||||
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::source_map::{BytePos, Span};
|
use syntax::source_map::{BytePos, Span};
|
||||||
use syntax_pos::Pos;
|
use syntax_pos::Pos;
|
||||||
@@ -43,11 +44,11 @@ declare_clippy_lint! {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Doc {
|
pub struct Doc {
|
||||||
valid_idents: Vec<String>,
|
valid_idents: FxHashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Doc {
|
impl Doc {
|
||||||
pub fn new(valid_idents: Vec<String>) -> Self {
|
pub fn new(valid_idents: FxHashSet<String>) -> Self {
|
||||||
Self { valid_idents }
|
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);
|
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 doc = String::new();
|
||||||
let mut spans = vec![];
|
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>)>>(
|
fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
|
||||||
cx: &EarlyContext<'_>,
|
cx: &EarlyContext<'_>,
|
||||||
valid_idents: &[String],
|
valid_idents: &FxHashSet<String>,
|
||||||
docs: Events,
|
docs: Events,
|
||||||
spans: &[(usize, Span)],
|
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 == '\'') {
|
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
|
||||||
// Trim punctuation as in `some comment (see foo::bar).`
|
// Trim punctuation as in `some comment (see foo::bar).`
|
||||||
// ^^
|
// ^^
|
||||||
// Or even as in `_foo bar_` which is emphasized.
|
// Or even as in `_foo bar_` which is emphasized.
|
||||||
let word = word.trim_matches(|c: char| !c.is_alphanumeric());
|
let word = word.trim_matches(|c: char| !c.is_alphanumeric());
|
||||||
|
|
||||||
if valid_idents.iter().any(|i| i == word) {
|
if valid_idents.contains(word) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 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.clone()));
|
||||||
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
|
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_late_lint_pass(box neg_multiply::NegMultiply);
|
||||||
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
|
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
|
||||||
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
|
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
|
||||||
|
|||||||
Reference in New Issue
Block a user