@@ -67,11 +67,8 @@ pub struct LintStore {
6767 /// Lints indexed by name.
6868 by_name : FxHashMap < String , TargetLint > ,
6969
70- /// Map of registered lint groups to what lints they expand to. The first
71- /// bool is true if the lint group was added by a plugin. The optional string
72- /// is used to store the new names of deprecated lint group names and is paired
73- /// with `true` if the deprecation is silent.
74- lint_groups : FxHashMap < & ' static str , ( Vec < LintId > , bool , Option < ( & ' static str , bool ) > ) > ,
70+ /// Map of registered lint groups to what lints they expand to.
71+ lint_groups : FxHashMap < & ' static str , LintGroup > ,
7572
7673 /// Extra info for future incompatibility lints, describing the
7774 /// issue or RFC that caused the incompatibility.
@@ -128,6 +125,18 @@ pub enum FindLintError {
128125 Removed ,
129126}
130127
128+ struct LintAlias {
129+ name : & ' static str ,
130+ /// Whether deprecation warnings should be suppressed for this alias.
131+ silent : bool ,
132+ }
133+
134+ struct LintGroup {
135+ lint_ids : Vec < LintId > ,
136+ from_plugin : bool ,
137+ depr : Option < LintAlias > ,
138+ }
139+
131140pub enum CheckLintNameResult < ' a > {
132141 Ok ( & ' a [ LintId ] ) ,
133142 /// Lint doesn't exist
@@ -162,8 +171,14 @@ impl LintStore {
162171
163172 pub fn get_lint_groups < ' t > ( & ' t self ) -> Vec < ( & ' static str , Vec < LintId > , bool ) > {
164173 self . lint_groups . iter ( )
165- . filter ( |( _, ( _, _, d) ) | d. is_none ( ) ) // Don't display deprecated lint groups.
166- . map ( |( k, v) | ( * k, v. 0 . clone ( ) , v. 1 ) ) . collect ( )
174+ . filter ( |( _, LintGroup { depr, .. } ) | {
175+ // Don't display deprecated lint groups.
176+ depr. is_none ( )
177+ } )
178+ . map ( |( k, LintGroup { lint_ids, from_plugin, .. } ) | {
179+ ( * k, lint_ids. clone ( ) , * from_plugin)
180+ } )
181+ . collect ( )
167182 }
168183
169184 pub fn register_early_pass ( & mut self ,
@@ -251,7 +266,11 @@ impl LintStore {
251266 lint_name : & ' static str ,
252267 alias : & ' static str ,
253268 ) {
254- self . lint_groups . insert ( alias, ( vec ! [ ] , false , Some ( ( lint_name, true ) ) ) ) ;
269+ self . lint_groups . insert ( alias, LintGroup {
270+ lint_ids : vec ! [ ] ,
271+ from_plugin : false ,
272+ depr : Some ( LintAlias { name : lint_name, silent : true } ) ,
273+ } ) ;
255274 }
256275
257276 pub fn register_group (
@@ -264,11 +283,18 @@ impl LintStore {
264283 ) {
265284 let new = self
266285 . lint_groups
267- . insert ( name, ( to, from_plugin, None ) )
286+ . insert ( name, LintGroup {
287+ lint_ids : to,
288+ from_plugin,
289+ depr : None ,
290+ } )
268291 . is_none ( ) ;
269292 if let Some ( deprecated) = deprecated_name {
270- self . lint_groups
271- . insert ( deprecated, ( vec ! [ ] , from_plugin, Some ( ( name, false ) ) ) ) ;
293+ self . lint_groups . insert ( deprecated, LintGroup {
294+ lint_ids : vec ! [ ] ,
295+ from_plugin,
296+ depr : Some ( LintAlias { name, silent : false } ) ,
297+ } ) ;
272298 }
273299
274300 if !new {
@@ -309,12 +335,12 @@ impl LintStore {
309335 None => {
310336 loop {
311337 return match self . lint_groups . get ( lint_name) {
312- Some ( ( ids , _ , depr) ) => {
313- if let Some ( ( name, _ ) ) = depr {
338+ Some ( LintGroup { lint_ids , depr, .. } ) => {
339+ if let Some ( LintAlias { name, .. } ) = depr {
314340 lint_name = name;
315341 continue ;
316342 }
317- Ok ( ids . clone ( ) )
343+ Ok ( lint_ids . clone ( ) )
318344 }
319345 None => Err ( FindLintError :: Removed )
320346 } ;
@@ -383,7 +409,9 @@ impl LintStore {
383409 match self . by_name . get ( & complete_name) {
384410 None => match self . lint_groups . get ( & * complete_name) {
385411 None => return CheckLintNameResult :: Tool ( Err ( ( None , String :: new ( ) ) ) ) ,
386- Some ( ids) => return CheckLintNameResult :: Tool ( Ok ( & ids. 0 ) ) ,
412+ Some ( LintGroup { lint_ids, .. } ) => {
413+ return CheckLintNameResult :: Tool ( Ok ( & lint_ids) ) ;
414+ }
387415 } ,
388416 Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Ok ( slice:: from_ref ( id) ) ) ,
389417 // If the lint was registered as removed or renamed by the lint tool, we don't need
@@ -407,20 +435,20 @@ impl LintStore {
407435 // If neither the lint, nor the lint group exists check if there is a `clippy::`
408436 // variant of this lint
409437 None => self . check_tool_name_for_backwards_compat ( & complete_name, "clippy" ) ,
410- Some ( ids ) => {
438+ Some ( LintGroup { lint_ids , depr , .. } ) => {
411439 // Check if the lint group name is deprecated
412- if let Some ( ( new_name , silent) ) = ids . 2 {
413- let lint_ids = self . lint_groups . get ( new_name ) . unwrap ( ) ;
414- return if silent {
415- CheckLintNameResult :: Ok ( & lint_ids. 0 )
440+ if let Some ( LintAlias { name , silent } ) = depr {
441+ let LintGroup { lint_ids, .. } = self . lint_groups . get ( name ) . unwrap ( ) ;
442+ return if * silent {
443+ CheckLintNameResult :: Ok ( & lint_ids)
416444 } else {
417445 CheckLintNameResult :: Tool ( Err ( (
418- Some ( & lint_ids. 0 ) ,
419- new_name . to_string ( ) ,
446+ Some ( & lint_ids) ,
447+ name . to_string ( ) ,
420448 ) ) )
421449 } ;
422450 }
423- CheckLintNameResult :: Ok ( & ids . 0 )
451+ CheckLintNameResult :: Ok ( & lint_ids )
424452 }
425453 } ,
426454 Some ( & Id ( ref id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
@@ -437,20 +465,20 @@ impl LintStore {
437465 None => match self . lint_groups . get ( & * complete_name) {
438466 // Now we are sure, that this lint exists nowhere
439467 None => CheckLintNameResult :: NoLint ,
440- Some ( ids ) => {
468+ Some ( LintGroup { lint_ids , depr , .. } ) => {
441469 // Reaching this would be weird, but let's cover this case anyway
442- if let Some ( ( new_name , silent) ) = ids . 2 {
443- let lint_ids = self . lint_groups . get ( new_name ) . unwrap ( ) ;
444- return if silent {
445- CheckLintNameResult :: Tool ( Err ( ( Some ( & lint_ids. 0 ) , complete_name) ) )
470+ if let Some ( LintAlias { name , silent } ) = depr {
471+ let LintGroup { lint_ids, .. } = self . lint_groups . get ( name ) . unwrap ( ) ;
472+ return if * silent {
473+ CheckLintNameResult :: Tool ( Err ( ( Some ( & lint_ids) , complete_name) ) )
446474 } else {
447475 CheckLintNameResult :: Tool ( Err ( (
448- Some ( & lint_ids. 0 ) ,
449- new_name . to_string ( ) ,
476+ Some ( & lint_ids) ,
477+ name . to_string ( ) ,
450478 ) ) )
451479 } ;
452480 }
453- CheckLintNameResult :: Tool ( Err ( ( Some ( & ids . 0 ) , complete_name) ) )
481+ CheckLintNameResult :: Tool ( Err ( ( Some ( & lint_ids ) , complete_name) ) )
454482 }
455483 } ,
456484 Some ( & Id ( ref id) ) => {
0 commit comments