@@ -139,7 +139,7 @@ pub enum CheckLintNameResult<'a> {
139
139
/// compiled with the tool and therefore the lint was never
140
140
/// added to the `LintStore`. Otherwise the `LintId` will be
141
141
/// returned as if it where a rustc lint.
142
- Tool ( Option < & ' a [ LintId ] > ) ,
142
+ Tool ( Result < & ' a [ LintId ] , ( Option < & ' a [ LintId ] > , String ) > ) ,
143
143
}
144
144
145
145
impl LintStore {
@@ -353,34 +353,79 @@ impl LintStore {
353
353
} else {
354
354
lint_name. to_string ( )
355
355
} ;
356
+ // If the lint was scoped with `tool::` check if the tool lint exists
356
357
if let Some ( _) = tool_name {
357
358
match self . by_name . get ( & complete_name) {
358
359
None => match self . lint_groups . get ( & * complete_name) {
359
- None => return CheckLintNameResult :: Tool ( None ) ,
360
- Some ( ids) => return CheckLintNameResult :: Tool ( Some ( & ids. 0 ) ) ,
360
+ None => return CheckLintNameResult :: Tool ( Err ( ( None , String :: new ( ) ) ) ) ,
361
+ Some ( ids) => return CheckLintNameResult :: Tool ( Ok ( & ids. 0 ) ) ,
361
362
} ,
362
- Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Some ( slice:: from_ref ( id) ) ) ,
363
+ Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Ok ( slice:: from_ref ( id) ) ) ,
363
364
// If the lint was registered as removed or renamed by the lint tool, we don't need
364
365
// to treat tool_lints and rustc lints different and can use the code below.
365
366
_ => { }
366
367
}
367
368
}
368
369
match self . by_name . get ( & complete_name) {
369
370
Some ( & Renamed ( ref new_name, _) ) => CheckLintNameResult :: Warning (
370
- format ! ( "lint `{}` has been renamed to `{}`" , lint_name, new_name) ,
371
+ format ! (
372
+ "lint `{}` has been renamed to `{}`" ,
373
+ complete_name, new_name
374
+ ) ,
371
375
Some ( new_name. to_owned ( ) ) ,
372
376
) ,
373
377
Some ( & Removed ( ref reason) ) => CheckLintNameResult :: Warning (
374
- format ! ( "lint `{}` has been removed: `{}`" , lint_name , reason) ,
378
+ format ! ( "lint `{}` has been removed: `{}`" , complete_name , reason) ,
375
379
None ,
376
380
) ,
377
381
None => match self . lint_groups . get ( & * complete_name) {
378
- None => CheckLintNameResult :: NoLint ,
379
- Some ( ids) => CheckLintNameResult :: Ok ( & ids. 0 ) ,
382
+ // If neither the lint, nor the lint group exists check if there is a `clippy::`
383
+ // variant of this lint
384
+ None => self . check_tool_name_for_backwards_compat ( & complete_name, "clippy" ) ,
385
+ Some ( ids) => {
386
+ // Check if the lint group name is deprecated
387
+ if let Some ( new_name) = ids. 2 {
388
+ let lint_ids = self . lint_groups . get ( new_name) . unwrap ( ) ;
389
+ return CheckLintNameResult :: Tool ( Err ( (
390
+ Some ( & lint_ids. 0 ) ,
391
+ new_name. to_string ( ) ,
392
+ ) ) ) ;
393
+ }
394
+ CheckLintNameResult :: Ok ( & ids. 0 )
395
+ }
380
396
} ,
381
397
Some ( & Id ( ref id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
382
398
}
383
399
}
400
+
401
+ fn check_tool_name_for_backwards_compat (
402
+ & self ,
403
+ lint_name : & str ,
404
+ tool_name : & str ,
405
+ ) -> CheckLintNameResult {
406
+ let complete_name = format ! ( "{}::{}" , tool_name, lint_name) ;
407
+ match self . by_name . get ( & complete_name) {
408
+ None => match self . lint_groups . get ( & * complete_name) {
409
+ // Now we are sure, that this lint exists nowhere
410
+ None => CheckLintNameResult :: NoLint ,
411
+ Some ( ids) => {
412
+ // Reaching this would be weird, but lets cover this case anyway
413
+ if let Some ( new_name) = ids. 2 {
414
+ let lint_ids = self . lint_groups . get ( new_name) . unwrap ( ) ;
415
+ return CheckLintNameResult :: Tool ( Err ( (
416
+ Some ( & lint_ids. 0 ) ,
417
+ new_name. to_string ( ) ,
418
+ ) ) ) ;
419
+ }
420
+ CheckLintNameResult :: Tool ( Ok ( & ids. 0 ) )
421
+ }
422
+ } ,
423
+ Some ( & Id ( ref id) ) => {
424
+ CheckLintNameResult :: Tool ( Err ( ( Some ( slice:: from_ref ( id) ) , complete_name) ) )
425
+ }
426
+ _ => CheckLintNameResult :: NoLint ,
427
+ }
428
+ }
384
429
}
385
430
386
431
/// Context for lint checking after type checking.
0 commit comments