@@ -67,10 +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.
73
- lint_groups : FxHashMap < & ' static str , ( Vec < LintId > , bool , Option < & ' static str > ) > ,
70
+ /// Map of registered lint groups to what lints they expand to.
71
+ lint_groups : FxHashMap < & ' static str , LintGroup > ,
74
72
75
73
/// Extra info for future incompatibility lints, describing the
76
74
/// issue or RFC that caused the incompatibility.
@@ -127,6 +125,18 @@ pub enum FindLintError {
127
125
Removed ,
128
126
}
129
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
+
130
140
pub enum CheckLintNameResult < ' a > {
131
141
Ok ( & ' a [ LintId ] ) ,
132
142
/// Lint doesn't exist
@@ -160,9 +170,15 @@ impl LintStore {
160
170
}
161
171
162
172
pub fn get_lint_groups < ' t > ( & ' t self ) -> Vec < ( & ' static str , Vec < LintId > , bool ) > {
163
- self . lint_groups . iter ( ) . map ( |( k, v) | ( * k,
164
- v. 0 . clone ( ) ,
165
- v. 1 ) ) . collect ( )
173
+ self . lint_groups . iter ( )
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 ( )
166
182
}
167
183
168
184
pub fn register_early_pass ( & mut self ,
@@ -245,6 +261,18 @@ impl LintStore {
245
261
self . future_incompatible . get ( & id)
246
262
}
247
263
264
+ pub fn register_group_alias (
265
+ & mut self ,
266
+ lint_name : & ' static str ,
267
+ alias : & ' static str ,
268
+ ) {
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
+ } ) ;
274
+ }
275
+
248
276
pub fn register_group (
249
277
& mut self ,
250
278
sess : Option < & Session > ,
@@ -255,11 +283,18 @@ impl LintStore {
255
283
) {
256
284
let new = self
257
285
. lint_groups
258
- . insert ( name, ( to, from_plugin, None ) )
286
+ . insert ( name, LintGroup {
287
+ lint_ids : to,
288
+ from_plugin,
289
+ depr : None ,
290
+ } )
259
291
. is_none ( ) ;
260
292
if let Some ( deprecated) = deprecated_name {
261
- self . lint_groups
262
- . insert ( deprecated, ( vec ! [ ] , from_plugin, Some ( name) ) ) ;
293
+ self . lint_groups . insert ( deprecated, LintGroup {
294
+ lint_ids : vec ! [ ] ,
295
+ from_plugin,
296
+ depr : Some ( LintAlias { name, silent : false } ) ,
297
+ } ) ;
263
298
}
264
299
265
300
if !new {
@@ -288,7 +323,7 @@ impl LintStore {
288
323
self . by_name . insert ( name. into ( ) , Removed ( reason. into ( ) ) ) ;
289
324
}
290
325
291
- pub fn find_lints ( & self , lint_name : & str ) -> Result < Vec < LintId > , FindLintError > {
326
+ pub fn find_lints ( & self , mut lint_name : & str ) -> Result < Vec < LintId > , FindLintError > {
292
327
match self . by_name . get ( lint_name) {
293
328
Some ( & Id ( lint_id) ) => Ok ( vec ! [ lint_id] ) ,
294
329
Some ( & Renamed ( _, lint_id) ) => {
@@ -298,9 +333,17 @@ impl LintStore {
298
333
Err ( FindLintError :: Removed )
299
334
} ,
300
335
None => {
301
- match self . lint_groups . get ( lint_name) {
302
- Some ( v) => Ok ( v. 0 . clone ( ) ) ,
303
- None => Err ( FindLintError :: Removed )
336
+ loop {
337
+ return match self . lint_groups . get ( lint_name) {
338
+ Some ( LintGroup { lint_ids, depr, .. } ) => {
339
+ if let Some ( LintAlias { name, .. } ) = depr {
340
+ lint_name = name;
341
+ continue ;
342
+ }
343
+ Ok ( lint_ids. clone ( ) )
344
+ }
345
+ None => Err ( FindLintError :: Removed )
346
+ } ;
304
347
}
305
348
}
306
349
}
@@ -366,7 +409,9 @@ impl LintStore {
366
409
match self . by_name . get ( & complete_name) {
367
410
None => match self . lint_groups . get ( & * complete_name) {
368
411
None => return CheckLintNameResult :: Tool ( Err ( ( None , String :: new ( ) ) ) ) ,
369
- Some ( ids) => return CheckLintNameResult :: Tool ( Ok ( & ids. 0 ) ) ,
412
+ Some ( LintGroup { lint_ids, .. } ) => {
413
+ return CheckLintNameResult :: Tool ( Ok ( & lint_ids) ) ;
414
+ }
370
415
} ,
371
416
Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Ok ( slice:: from_ref ( id) ) ) ,
372
417
// If the lint was registered as removed or renamed by the lint tool, we don't need
@@ -390,16 +435,20 @@ impl LintStore {
390
435
// If neither the lint, nor the lint group exists check if there is a `clippy::`
391
436
// variant of this lint
392
437
None => self . check_tool_name_for_backwards_compat ( & complete_name, "clippy" ) ,
393
- Some ( ids ) => {
438
+ Some ( LintGroup { lint_ids , depr , .. } ) => {
394
439
// Check if the lint group name is deprecated
395
- if let Some ( new_name) = ids. 2 {
396
- let lint_ids = self . lint_groups . get ( new_name) . unwrap ( ) ;
397
- return CheckLintNameResult :: Tool ( Err ( (
398
- Some ( & lint_ids. 0 ) ,
399
- new_name. to_string ( ) ,
400
- ) ) ) ;
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)
444
+ } else {
445
+ CheckLintNameResult :: Tool ( Err ( (
446
+ Some ( & lint_ids) ,
447
+ name. to_string ( ) ,
448
+ ) ) )
449
+ } ;
401
450
}
402
- CheckLintNameResult :: Ok ( & ids . 0 )
451
+ CheckLintNameResult :: Ok ( & lint_ids )
403
452
}
404
453
} ,
405
454
Some ( & Id ( ref id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
@@ -416,16 +465,20 @@ impl LintStore {
416
465
None => match self . lint_groups . get ( & * complete_name) {
417
466
// Now we are sure, that this lint exists nowhere
418
467
None => CheckLintNameResult :: NoLint ,
419
- Some ( ids) => {
420
- // Reaching this would be weird, but lets cover this case anyway
421
- if let Some ( new_name) = ids. 2 {
422
- let lint_ids = self . lint_groups . get ( new_name) . unwrap ( ) ;
423
- return CheckLintNameResult :: Tool ( Err ( (
424
- Some ( & lint_ids. 0 ) ,
425
- new_name. to_string ( ) ,
426
- ) ) ) ;
468
+ Some ( LintGroup { lint_ids, depr, .. } ) => {
469
+ // Reaching this would be weird, but let's cover this case anyway
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) ) )
474
+ } else {
475
+ CheckLintNameResult :: Tool ( Err ( (
476
+ Some ( & lint_ids) ,
477
+ name. to_string ( ) ,
478
+ ) ) )
479
+ } ;
427
480
}
428
- CheckLintNameResult :: Tool ( Err ( ( Some ( & ids . 0 ) , complete_name) ) )
481
+ CheckLintNameResult :: Tool ( Err ( ( Some ( & lint_ids ) , complete_name) ) )
429
482
}
430
483
} ,
431
484
Some ( & Id ( ref id) ) => {
0 commit comments