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:: intravisit:: { self , Visitor } ;
6
6
use rustc_hir:: HirId ;
@@ -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) ;
@@ -133,11 +133,11 @@ pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<Str
133
133
let group_name = name_without_tool ( & binding) . to_string ( ) ;
134
134
if visitor. lints_that_actually_run . contains ( & group_name) {
135
135
for lint in group. 1 {
136
- visitor. lints_that_actually_run . 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
}
@@ -347,20 +347,24 @@ struct LintLevelMinimum<'tcx> {
347
347
348
348
impl < ' tcx > LintLevelMinimum < ' tcx > {
349
349
pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
350
+ let mut lints_that_actually_run = FxIndexSet :: default ( ) ;
351
+ lints_that_actually_run. reserve ( 230 ) ;
352
+ let mut lints_allowed = FxIndexSet :: default ( ) ;
353
+ lints_allowed. reserve ( 100 ) ;
350
354
Self {
351
355
tcx,
352
356
// That magic number is the current number of lints + some more for possible future lints
353
- lints_that_actually_run : Vec :: with_capacity ( 230 ) ,
354
- lints_allowed : Vec :: with_capacity ( 100 ) ,
357
+ lints_that_actually_run,
358
+ lints_allowed,
355
359
}
356
360
}
357
361
358
362
fn process_opts ( & mut self ) {
359
363
for ( lint, level) in & self . tcx . sess . opts . lint_opts {
360
364
if * level == Level :: Allow {
361
- self . lints_allowed . push ( lint. clone ( ) ) ;
365
+ self . lints_allowed . insert ( lint. clone ( ) ) ;
362
366
} else {
363
- self . lints_that_actually_run . push ( lint. to_string ( ) ) ;
367
+ self . lints_that_actually_run . insert ( lint. to_string ( ) ) ;
364
368
}
365
369
}
366
370
}
@@ -385,13 +389,13 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
385
389
// If it's a tool lint (e.g. clippy::my_clippy_lint)
386
390
if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
387
391
if meta_item. path . segments . len ( ) == 1 {
388
- self . lints_that_actually_run . push (
392
+ self . lints_that_actually_run . insert (
389
393
// SAFETY: Lint attributes can only have literals
390
394
meta_list. ident ( ) . unwrap ( ) . name . as_str ( ) . to_string ( ) ,
391
395
) ;
392
396
} else {
393
397
self . lints_that_actually_run
394
- . push ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
398
+ . insert ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
395
399
}
396
400
}
397
401
}
@@ -403,10 +407,10 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
403
407
// If it's a tool lint (e.g. clippy::my_clippy_lint)
404
408
if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
405
409
if meta_item. path . segments . len ( ) == 1 {
406
- self . lints_allowed . push ( meta_list. name_or_empty ( ) . as_str ( ) . to_string ( ) )
410
+ self . lints_allowed . insert ( meta_list. name_or_empty ( ) . as_str ( ) . to_string ( ) ) ;
407
411
} else {
408
412
self . lints_allowed
409
- . push ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
413
+ . insert ( meta_item. path . segments [ 1 ] . ident . name . as_str ( ) . to_string ( ) ) ;
410
414
}
411
415
}
412
416
}
0 commit comments