@@ -83,11 +83,6 @@ enum TargetLint {
83
83
Ignored ,
84
84
}
85
85
86
- pub enum FindLintError {
87
- NotFound ,
88
- Removed ,
89
- }
90
-
91
86
struct LintAlias {
92
87
name : & ' static str ,
93
88
/// Whether deprecation warnings should be suppressed for this alias.
@@ -231,13 +226,24 @@ impl LintStore {
231
226
}
232
227
}
233
228
234
- pub fn register_group_alias ( & mut self , lint_name : & ' static str , alias : & ' static str ) {
235
- self . lint_groups . insert (
229
+ fn insert_group ( & mut self , name : & ' static str , group : LintGroup ) {
230
+ let previous = self . lint_groups . insert ( name, group) ;
231
+ if previous. is_some ( ) {
232
+ bug ! ( "group {name:?} already exists" ) ;
233
+ }
234
+ }
235
+
236
+ pub fn register_group_alias ( & mut self , group_name : & ' static str , alias : & ' static str ) {
237
+ let Some ( LintGroup { lint_ids, .. } ) = self . lint_groups . get ( group_name) else {
238
+ bug ! ( "group alias {alias:?} points to unregistered group {group_name:?}" )
239
+ } ;
240
+
241
+ self . insert_group (
236
242
alias,
237
243
LintGroup {
238
- lint_ids : vec ! [ ] ,
244
+ lint_ids : lint_ids . clone ( ) ,
239
245
is_externally_loaded : false ,
240
- depr : Some ( LintAlias { name : lint_name , silent : true } ) ,
246
+ depr : Some ( LintAlias { name : group_name , silent : true } ) ,
241
247
} ,
242
248
) ;
243
249
}
@@ -249,24 +255,17 @@ impl LintStore {
249
255
deprecated_name : Option < & ' static str > ,
250
256
to : Vec < LintId > ,
251
257
) {
252
- let new = self
253
- . lint_groups
254
- . insert ( name, LintGroup { lint_ids : to, is_externally_loaded, depr : None } )
255
- . is_none ( ) ;
256
258
if let Some ( deprecated) = deprecated_name {
257
- self . lint_groups . insert (
259
+ self . insert_group (
258
260
deprecated,
259
261
LintGroup {
260
- lint_ids : vec ! [ ] ,
262
+ lint_ids : to . clone ( ) ,
261
263
is_externally_loaded,
262
264
depr : Some ( LintAlias { name, silent : false } ) ,
263
265
} ,
264
266
) ;
265
267
}
266
-
267
- if !new {
268
- bug ! ( "duplicate specification of lint group {}" , name) ;
269
- }
268
+ self . insert_group ( name, LintGroup { lint_ids : to, is_externally_loaded, depr : None } ) ;
270
269
}
271
270
272
271
/// This lint should give no warning and have no effect.
@@ -292,23 +291,15 @@ impl LintStore {
292
291
self . by_name . insert ( name. into ( ) , Removed ( reason. into ( ) ) ) ;
293
292
}
294
293
295
- pub fn find_lints ( & self , mut lint_name : & str ) -> Result < Vec < LintId > , FindLintError > {
294
+ pub fn find_lints ( & self , lint_name : & str ) -> Option < & [ LintId ] > {
296
295
match self . by_name . get ( lint_name) {
297
- Some ( & Id ( lint_id) ) => Ok ( vec ! [ lint_id] ) ,
298
- Some ( & Renamed ( _, lint_id) ) => Ok ( vec ! [ lint_id] ) ,
299
- Some ( & Removed ( _) ) => Err ( FindLintError :: Removed ) ,
300
- Some ( & Ignored ) => Ok ( vec ! [ ] ) ,
301
- None => loop {
302
- return match self . lint_groups . get ( lint_name) {
303
- Some ( LintGroup { lint_ids, depr, .. } ) => {
304
- if let Some ( LintAlias { name, .. } ) = depr {
305
- lint_name = name;
306
- continue ;
307
- }
308
- Ok ( lint_ids. clone ( ) )
309
- }
310
- None => Err ( FindLintError :: Removed ) ,
311
- } ;
296
+ Some ( Id ( lint_id) ) => Some ( slice:: from_ref ( lint_id) ) ,
297
+ Some ( Renamed ( _, lint_id) ) => Some ( slice:: from_ref ( lint_id) ) ,
298
+ Some ( Removed ( _) ) => None ,
299
+ Some ( Ignored ) => Some ( & [ ] ) ,
300
+ None => match self . lint_groups . get ( lint_name) {
301
+ Some ( LintGroup { lint_ids, .. } ) => Some ( lint_ids) ,
302
+ None => None ,
312
303
} ,
313
304
}
314
305
}
@@ -374,8 +365,12 @@ impl LintStore {
374
365
CheckLintNameResult :: MissingTool
375
366
} ;
376
367
}
377
- Some ( LintGroup { lint_ids, .. } ) => {
378
- return CheckLintNameResult :: Tool ( lint_ids, None ) ;
368
+ Some ( LintGroup { lint_ids, depr, .. } ) => {
369
+ return if let & Some ( LintAlias { name, silent : false } ) = depr {
370
+ CheckLintNameResult :: Tool ( lint_ids, Some ( name. to_string ( ) ) )
371
+ } else {
372
+ CheckLintNameResult :: Tool ( lint_ids, None )
373
+ } ;
379
374
}
380
375
} ,
381
376
Some ( Id ( id) ) => return CheckLintNameResult :: Tool ( slice:: from_ref ( id) , None ) ,
@@ -393,15 +388,11 @@ impl LintStore {
393
388
None => self . check_tool_name_for_backwards_compat ( & complete_name, "clippy" ) ,
394
389
Some ( LintGroup { lint_ids, depr, .. } ) => {
395
390
// Check if the lint group name is deprecated
396
- if let Some ( LintAlias { name, silent } ) = depr {
397
- let LintGroup { lint_ids, .. } = self . lint_groups . get ( name) . unwrap ( ) ;
398
- return if * silent {
399
- CheckLintNameResult :: Ok ( lint_ids)
400
- } else {
401
- CheckLintNameResult :: Tool ( lint_ids, Some ( ( * name) . to_string ( ) ) )
402
- } ;
391
+ if let & Some ( LintAlias { name, silent : false } ) = depr {
392
+ CheckLintNameResult :: Tool ( lint_ids, Some ( name. to_string ( ) ) )
393
+ } else {
394
+ CheckLintNameResult :: Ok ( lint_ids)
403
395
}
404
- CheckLintNameResult :: Ok ( lint_ids)
405
396
}
406
397
} ,
407
398
Some ( Id ( id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
@@ -412,7 +403,7 @@ impl LintStore {
412
403
fn no_lint_suggestion ( & self , lint_name : & str , tool_name : & str ) -> CheckLintNameResult < ' _ > {
413
404
let name_lower = lint_name. to_lowercase ( ) ;
414
405
415
- if lint_name. chars ( ) . any ( char:: is_uppercase) && self . find_lints ( & name_lower) . is_ok ( ) {
406
+ if lint_name. chars ( ) . any ( char:: is_uppercase) && self . find_lints ( & name_lower) . is_some ( ) {
416
407
// First check if the lint name is (partly) in upper case instead of lower case...
417
408
return CheckLintNameResult :: NoLint ( Some ( ( Symbol :: intern ( & name_lower) , false ) ) ) ;
418
409
}
@@ -455,18 +446,8 @@ impl LintStore {
455
446
None => match self . lint_groups . get ( & * complete_name) {
456
447
// Now we are sure, that this lint exists nowhere
457
448
None => self . no_lint_suggestion ( lint_name, tool_name) ,
458
- Some ( LintGroup { lint_ids, depr, .. } ) => {
459
- // Reaching this would be weird, but let's cover this case anyway
460
- if let Some ( LintAlias { name, silent } ) = depr {
461
- let LintGroup { lint_ids, .. } = self . lint_groups . get ( name) . unwrap ( ) ;
462
- if * silent {
463
- CheckLintNameResult :: Tool ( lint_ids, Some ( complete_name) )
464
- } else {
465
- CheckLintNameResult :: Tool ( lint_ids, Some ( ( * name) . to_string ( ) ) )
466
- }
467
- } else {
468
- CheckLintNameResult :: Tool ( lint_ids, Some ( complete_name) )
469
- }
449
+ Some ( LintGroup { lint_ids, .. } ) => {
450
+ CheckLintNameResult :: Tool ( lint_ids, Some ( complete_name) )
470
451
}
471
452
} ,
472
453
Some ( Id ( id) ) => CheckLintNameResult :: Tool ( slice:: from_ref ( id) , Some ( complete_name) ) ,
0 commit comments