11use 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 } ;
44use rustc_feature:: { Features , GateIssue } ;
55use rustc_hir:: HirId ;
66use rustc_hir:: intravisit:: { self , Visitor } ;
@@ -120,7 +120,7 @@ impl LintLevelSets {
120120/// (and not allowed in the crate) and CLI lints. The returned value is a tuple
121121/// of 1. The lints that will emit (or at least, should run), and 2.
122122/// 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 > ) > {
124124 let mut visitor = LintLevelMinimum :: new ( tcx) ;
125125 visitor. process_opts ( ) ;
126126 tcx. hir ( ) . walk_attributes ( & mut visitor) ;
@@ -131,18 +131,18 @@ pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<String>, Vec<Str
131131 for group in lint_groups {
132132 let binding = group. 0 . to_lowercase ( ) ;
133133 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) {
135135 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 ( ) ) ;
137137 }
138138 } else if visitor. lints_allowed . contains ( & group_name) {
139139 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 ( ) ) ;
141141 }
142142 }
143143 }
144144
145- Lrc :: new ( ( visitor. lints_to_emit , visitor. lints_allowed ) )
145+ Lrc :: new ( ( visitor. lints_that_actually_run , visitor. lints_allowed ) )
146146}
147147
148148#[ instrument( level = "trace" , skip( tcx) , ret) ]
@@ -339,26 +339,30 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
339339struct LintLevelMinimum < ' tcx > {
340340 tcx : TyCtxt < ' tcx > ,
341341 /// 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 > ,
344344}
345345
346346impl < ' tcx > LintLevelMinimum < ' tcx > {
347347 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 ) ;
348352 Self {
349353 tcx,
350354 // 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,
353357 }
354358 }
355359
356360 fn process_opts ( & mut self ) {
357361 for ( lint, level) in & self . tcx . sess . opts . lint_opts {
358362 if * level == Level :: Allow {
359- self . lints_allowed . push ( lint. clone ( ) ) ;
363+ self . lints_allowed . insert ( lint. clone ( ) ) ;
360364 } else {
361- self . lints_to_emit . push ( lint. to_string ( ) ) ;
365+ self . lints_that_actually_run . insert ( lint. to_string ( ) ) ;
362366 }
363367 }
364368 }
@@ -383,13 +387,13 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
383387 // If it's a tool lint (e.g. clippy::my_clippy_lint)
384388 if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
385389 if meta_item. path . segments . len ( ) == 1 {
386- self . lints_to_emit . push (
390+ self . lints_that_actually_run . insert (
387391 // SAFETY: Lint attributes can only have literals
388392 meta_list. ident ( ) . unwrap ( ) . name . as_str ( ) . to_string ( ) ,
389393 ) ;
390394 } 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 ( ) ) ;
393397 }
394398 }
395399 }
@@ -401,10 +405,10 @@ impl<'tcx> Visitor<'tcx> for LintLevelMinimum<'tcx> {
401405 // If it's a tool lint (e.g. clippy::my_clippy_lint)
402406 if let ast:: NestedMetaItem :: MetaItem ( meta_item) = meta_list {
403407 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 ( ) ) ;
405409 } else {
406410 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 ( ) ) ;
408412 }
409413 }
410414 }
0 commit comments