1
1
use rustc_ast_pretty:: pprust;
2
- use rustc_data_structures:: { fx:: FxIndexMap , sync:: Lrc } ;
3
- use rustc_errors:: { Diag , DiagMessage , LintDiagnostic , MultiSpan } ;
2
+ use rustc_data_structures:: { fx:: FxIndexMap , fx :: FxIndexSet , sync:: Lrc } ;
3
+ use rustc_errors:: { Diag , LintDiagnostic , MultiSpan } ;
4
4
use rustc_feature:: { Features , GateIssue } ;
5
5
use rustc_hir:: HirId ;
6
6
use rustc_hir:: intravisit:: { self , Visitor } ;
@@ -120,7 +120,7 @@ impl LintLevelSets {
120
120
/// (and not allowed in the crate) and CLI lints. The returned value is a tuple
121
121
/// of 1. The lints that will emit (or at least, should run), and 2.
122
122
/// The lints that are allowed at the crate level and will not emit.
123
- pub fn lints_that_can_emit ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Lrc < ( Vec < String > , Vec < String > ) > {
123
+ pub fn lints_that_can_emit ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Lrc < ( FxIndexSet < String > , FxIndexSet < String > ) > {
124
124
let mut visitor = LintLevelMinimum :: new ( tcx) ;
125
125
visitor. process_opts ( ) ;
126
126
tcx. hir ( ) . walk_attributes ( & mut visitor) ;
@@ -131,18 +131,18 @@ pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<Str
131
131
for group in lint_groups {
132
132
let binding = group. 0 . to_lowercase ( ) ;
133
133
let group_name = name_without_tool ( & binding) . to_string ( ) ;
134
- if visitor. lints_to_emit . contains ( & group_name) {
134
+ if visitor. lints_that_actually_run . contains ( & group_name) {
135
135
for lint in group. 1 {
136
- visitor. lints_to_emit . push ( name_without_tool ( & lint. to_string ( ) ) . to_string ( ) ) ;
136
+ visitor. lints_that_actually_run . insert ( name_without_tool ( & lint. to_string ( ) ) . to_string ( ) ) ;
137
137
}
138
138
} else if visitor. lints_allowed . contains ( & group_name) {
139
139
for lint in & group. 1 {
140
- visitor. lints_allowed . push ( name_without_tool ( & lint. to_string ( ) ) . to_string ( ) ) ;
140
+ visitor. lints_allowed . insert ( name_without_tool ( & lint. to_string ( ) ) . to_string ( ) ) ;
141
141
}
142
142
}
143
143
}
144
144
145
- Lrc :: new ( ( visitor. lints_to_emit , visitor. lints_allowed ) )
145
+ Lrc :: new ( ( visitor. lints_that_actually_run , visitor. lints_allowed ) )
146
146
}
147
147
148
148
#[ instrument( level = "trace" , skip( tcx) , ret) ]
@@ -339,26 +339,30 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
339
339
struct LintLevelMinimum < ' tcx > {
340
340
tcx : TyCtxt < ' tcx > ,
341
341
/// The actual list of detected lints.
342
- lints_to_emit : Vec < String > ,
343
- lints_allowed : Vec < String > ,
342
+ lints_that_actually_run : FxIndexSet < String > ,
343
+ lints_allowed : FxIndexSet < String > ,
344
344
}
345
345
346
346
impl < ' tcx > LintLevelMinimum < ' tcx > {
347
347
pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
348
+ let mut lints_that_actually_run = FxIndexSet :: default ( ) ;
349
+ lints_that_actually_run. reserve ( 230 ) ;
350
+ let mut lints_allowed = FxIndexSet :: default ( ) ;
351
+ lints_allowed. reserve ( 100 ) ;
348
352
Self {
349
353
tcx,
350
354
// That magic number is the current number of lints + some more for possible future lints
351
- lints_to_emit : Vec :: with_capacity ( 230 ) ,
352
- lints_allowed : Vec :: with_capacity ( 100 ) ,
355
+ lints_that_actually_run ,
356
+ lints_allowed,
353
357
}
354
358
}
355
359
356
360
fn process_opts ( & mut self ) {
357
361
for ( lint, level) in & self . tcx . sess . opts . lint_opts {
358
362
if * level == Level :: Allow {
359
- self . lints_allowed . push ( lint. clone ( ) ) ;
363
+ self . lints_allowed . insert ( lint. clone ( ) ) ;
360
364
} else {
361
- self . lints_to_emit . push ( lint. to_string ( ) ) ;
365
+ self . lints_that_actually_run . insert ( lint. to_string ( ) ) ;
362
366
}
363
367
}
364
368
}
@@ -383,13 +387,13 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
383
387
// If it's a tool lint (e.g. clippy::my_clippy_lint)
384
388
if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
385
389
if meta_item. path . segments . len ( ) == 1 {
386
- self . lints_to_emit . push (
390
+ self . lints_that_actually_run . insert (
387
391
// SAFETY: Lint attributes can only have literals
388
392
meta_list. ident ( ) . unwrap ( ) . name . as_str ( ) . to_string ( ) ,
389
393
) ;
390
394
} else {
391
- self . lints_to_emit
392
- . push ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
395
+ self . lints_that_actually_run
396
+ . insert ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
393
397
}
394
398
}
395
399
}
@@ -401,10 +405,10 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
401
405
// If it's a tool lint (e.g. clippy::my_clippy_lint)
402
406
if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
403
407
if meta_item. path . segments . len ( ) == 1 {
404
- self . lints_allowed . push ( meta_list. name_or_empty ( ) . as_str ( ) . to_string ( ) )
408
+ self . lints_allowed . insert ( meta_list. name_or_empty ( ) . as_str ( ) . to_string ( ) ) ;
405
409
} else {
406
410
self . lints_allowed
407
- . push ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
411
+ . insert ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
408
412
}
409
413
}
410
414
}
0 commit comments