@@ -12,6 +12,7 @@ use itertools::Itertools;
12
12
use pulldown_cmark;
13
13
use rustc:: lint:: { EarlyContext , EarlyLintPass , LintArray , LintPass } ;
14
14
use rustc:: { declare_tool_lint, lint_array} ;
15
+ use rustc_data_structures:: fx:: FxHashSet ;
15
16
use syntax:: ast;
16
17
use syntax:: source_map:: { BytePos , Span } ;
17
18
use syntax_pos:: Pos ;
@@ -43,11 +44,11 @@ declare_clippy_lint! {
43
44
44
45
#[ derive( Clone ) ]
45
46
pub struct Doc {
46
- valid_idents : Vec < String > ,
47
+ valid_idents : FxHashSet < String > ,
47
48
}
48
49
49
50
impl Doc {
50
- pub fn new ( valid_idents : Vec < String > ) -> Self {
51
+ pub fn new ( valid_idents : FxHashSet < String > ) -> Self {
51
52
Self { valid_idents }
52
53
}
53
54
}
@@ -144,7 +145,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
144
145
panic ! ( "not a doc-comment: {}" , comment) ;
145
146
}
146
147
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 ] ) {
148
149
let mut doc = String :: new ( ) ;
149
150
let mut spans = vec ! [ ] ;
150
151
@@ -192,7 +193,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'
192
193
193
194
fn check_doc < ' a , Events : Iterator < Item = ( usize , pulldown_cmark:: Event < ' a > ) > > (
194
195
cx : & EarlyContext < ' _ > ,
195
- valid_idents : & [ String ] ,
196
+ valid_idents : & FxHashSet < String > ,
196
197
docs : Events ,
197
198
spans : & [ ( usize , Span ) ] ,
198
199
) {
@@ -237,14 +238,14 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
237
238
}
238
239
}
239
240
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 ) {
241
242
for word in text. split ( |c : char | c. is_whitespace ( ) || c == '\'' ) {
242
243
// Trim punctuation as in `some comment (see foo::bar).`
243
244
// ^^
244
245
// Or even as in `_foo bar_` which is emphasized.
245
246
let word = word. trim_matches ( |c : char | !c. is_alphanumeric ( ) ) ;
246
247
247
- if valid_idents. iter ( ) . any ( |i| i == word) {
248
+ if valid_idents. contains ( word) {
248
249
continue ;
249
250
}
250
251
0 commit comments