@@ -67,11 +67,8 @@ pub struct LintStore {
67
67
/// Lints indexed by name.
68
68
by_name : FxHashMap < String , TargetLint > ,
69
69
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 > ,
75
72
76
73
/// Extra info for future incompatibility lints, describing the
77
74
/// issue or RFC that caused the incompatibility.
@@ -128,6 +125,18 @@ pub enum FindLintError {
128
125
Removed ,
129
126
}
130
127
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
+
131
140
pub enum CheckLintNameResult < ' a > {
132
141
Ok ( & ' a [ LintId ] ) ,
133
142
/// Lint doesn't exist
@@ -162,8 +171,14 @@ impl LintStore {
162
171
163
172
pub fn get_lint_groups < ' t > ( & ' t self ) -> Vec < ( & ' static str , Vec < LintId > , bool ) > {
164
173
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 ( )
167
182
}
168
183
169
184
pub fn register_early_pass ( & mut self ,
@@ -251,7 +266,11 @@ impl LintStore {
251
266
lint_name : & ' static str ,
252
267
alias : & ' static str ,
253
268
) {
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
+ } ) ;
255
274
}
256
275
257
276
pub fn register_group (
@@ -264,11 +283,18 @@ impl LintStore {
264
283
) {
265
284
let new = self
266
285
. lint_groups
267
- . insert ( name, ( to, from_plugin, None ) )
286
+ . insert ( name, LintGroup {
287
+ lint_ids : to,
288
+ from_plugin,
289
+ depr : None ,
290
+ } )
268
291
. is_none ( ) ;
269
292
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
+ } ) ;
272
298
}
273
299
274
300
if !new {
@@ -309,12 +335,12 @@ impl LintStore {
309
335
None => {
310
336
loop {
311
337
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 {
314
340
lint_name = name;
315
341
continue ;
316
342
}
317
- Ok ( ids . clone ( ) )
343
+ Ok ( lint_ids . clone ( ) )
318
344
}
319
345
None => Err ( FindLintError :: Removed )
320
346
} ;
@@ -383,7 +409,9 @@ impl LintStore {
383
409
match self . by_name . get ( & complete_name) {
384
410
None => match self . lint_groups . get ( & * complete_name) {
385
411
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
+ }
387
415
} ,
388
416
Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Ok ( slice:: from_ref ( id) ) ) ,
389
417
// If the lint was registered as removed or renamed by the lint tool, we don't need
@@ -407,20 +435,20 @@ impl LintStore {
407
435
// If neither the lint, nor the lint group exists check if there is a `clippy::`
408
436
// variant of this lint
409
437
None => self . check_tool_name_for_backwards_compat ( & complete_name, "clippy" ) ,
410
- Some ( ids ) => {
438
+ Some ( LintGroup { lint_ids , depr , .. } ) => {
411
439
// 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)
416
444
} else {
417
445
CheckLintNameResult :: Tool ( Err ( (
418
- Some ( & lint_ids. 0 ) ,
419
- new_name . to_string ( ) ,
446
+ Some ( & lint_ids) ,
447
+ name . to_string ( ) ,
420
448
) ) )
421
449
} ;
422
450
}
423
- CheckLintNameResult :: Ok ( & ids . 0 )
451
+ CheckLintNameResult :: Ok ( & lint_ids )
424
452
}
425
453
} ,
426
454
Some ( & Id ( ref id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
@@ -437,20 +465,20 @@ impl LintStore {
437
465
None => match self . lint_groups . get ( & * complete_name) {
438
466
// Now we are sure, that this lint exists nowhere
439
467
None => CheckLintNameResult :: NoLint ,
440
- Some ( ids ) => {
468
+ Some ( LintGroup { lint_ids , depr , .. } ) => {
441
469
// 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) ) )
446
474
} else {
447
475
CheckLintNameResult :: Tool ( Err ( (
448
- Some ( & lint_ids. 0 ) ,
449
- new_name . to_string ( ) ,
476
+ Some ( & lint_ids) ,
477
+ name . to_string ( ) ,
450
478
) ) )
451
479
} ;
452
480
}
453
- CheckLintNameResult :: Tool ( Err ( ( Some ( & ids . 0 ) , complete_name) ) )
481
+ CheckLintNameResult :: Tool ( Err ( ( Some ( & lint_ids ) , complete_name) ) )
454
482
}
455
483
} ,
456
484
Some ( & Id ( ref id) ) => {
0 commit comments