@@ -28,7 +28,7 @@ use std::path::Path;
28
28
29
29
use crate :: utils:: internal_lints:: is_lint_ref_type;
30
30
use clippy_utils:: {
31
- diagnostics:: span_lint, last_path_segment, match_function_call, match_path, paths, ty:: match_type,
31
+ diagnostics:: span_lint, last_path_segment, match_def_path , match_function_call, match_path, paths, ty:: match_type,
32
32
ty:: walk_ptrs_ty_depth,
33
33
} ;
34
34
@@ -41,6 +41,8 @@ const BLACK_LISTED_LINTS: [&str; 3] = ["lint_author", "deep_code_inspection", "i
41
41
const IGNORED_LINT_GROUPS : [ & str ; 1 ] = [ "clippy::all" ] ;
42
42
/// Lints within this group will be excluded from the collection
43
43
const EXCLUDED_LINT_GROUPS : [ & str ; 1 ] = [ "clippy::internal" ] ;
44
+ /// Collected depreciated lint will be assigned to this group in the JSON output
45
+ const DEPRECIATED_LINT_GROUP_STR : & str = "DEPRECIATED" ;
44
46
45
47
const LINT_EMISSION_FUNCTIONS : [ & [ & str ] ; 7 ] = [
46
48
& [ "clippy_utils" , "diagnostics" , "span_lint" ] ,
@@ -66,6 +68,7 @@ const SUGGESTION_FUNCTIONS: [&[&str]; 2] = [
66
68
& [ "clippy_utils" , "diagnostics" , "multispan_sugg" ] ,
67
69
& [ "clippy_utils" , "diagnostics" , "multispan_sugg_with_applicability" ] ,
68
70
] ;
71
+ const DEPRECIATED_LINT_TYPE : [ & str ; 3 ] = [ "clippy_lints" , "deprecated_lints" , "ClippyDepreciatedLint" ] ;
69
72
70
73
/// The index of the applicability name of `paths::APPLICABILITY_VALUES`
71
74
const APPLICABILITY_NAME_INDEX : usize = 2 ;
@@ -225,23 +228,42 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
225
228
/// }
226
229
/// ```
227
230
fn check_item ( & mut self , cx : & LateContext < ' hir > , item : & ' hir Item < ' _ > ) {
228
- if_chain ! {
229
- // item validation
230
- if let ItemKind :: Static ( ref ty, Mutability :: Not , _) = item. kind;
231
- if is_lint_ref_type( cx, ty) ;
232
- // blacklist check
233
- let lint_name = sym_to_string( item. ident. name) . to_ascii_lowercase( ) ;
234
- if !BLACK_LISTED_LINTS . contains( & lint_name. as_str( ) ) ;
235
- // metadata extraction
236
- if let Some ( group) = get_lint_group_or_lint( cx, & lint_name, item) ;
237
- if let Some ( docs) = extract_attr_docs_or_lint( cx, item) ;
238
- then {
239
- self . lints. push( LintMetadata :: new(
240
- lint_name,
241
- SerializableSpan :: from_item( cx, item) ,
242
- group,
243
- docs,
244
- ) ) ;
231
+ if let ItemKind :: Static ( ref ty, Mutability :: Not , _) = item. kind {
232
+ // Normal lint
233
+ if_chain ! {
234
+ // item validation
235
+ if is_lint_ref_type( cx, ty) ;
236
+ // blacklist check
237
+ let lint_name = sym_to_string( item. ident. name) . to_ascii_lowercase( ) ;
238
+ if !BLACK_LISTED_LINTS . contains( & lint_name. as_str( ) ) ;
239
+ // metadata extraction
240
+ if let Some ( group) = get_lint_group_or_lint( cx, & lint_name, item) ;
241
+ if let Some ( docs) = extract_attr_docs_or_lint( cx, item) ;
242
+ then {
243
+ self . lints. push( LintMetadata :: new(
244
+ lint_name,
245
+ SerializableSpan :: from_item( cx, item) ,
246
+ group,
247
+ docs,
248
+ ) ) ;
249
+ }
250
+ }
251
+
252
+ if_chain ! {
253
+ if is_depreciated_lint( cx, ty) ;
254
+ // blacklist check
255
+ let lint_name = sym_to_string( item. ident. name) . to_ascii_lowercase( ) ;
256
+ if !BLACK_LISTED_LINTS . contains( & lint_name. as_str( ) ) ;
257
+ // Metadata the little we can get from a depreciated lint
258
+ if let Some ( docs) = extract_attr_docs_or_lint( cx, item) ;
259
+ then {
260
+ self . lints. push( LintMetadata :: new(
261
+ lint_name,
262
+ SerializableSpan :: from_item( cx, item) ,
263
+ DEPRECIATED_LINT_GROUP_STR . to_string( ) ,
264
+ docs,
265
+ ) ) ;
266
+ }
245
267
}
246
268
}
247
269
}
@@ -268,7 +290,7 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
268
290
// - src/misc.rs:734:9
269
291
// - src/methods/mod.rs:3545:13
270
292
// - src/methods/mod.rs:3496:13
271
- // We are basically unable to resolve the lint name it self .
293
+ // We are basically unable to resolve the lint name itself .
272
294
return ;
273
295
}
274
296
@@ -347,6 +369,16 @@ fn get_lint_group(cx: &LateContext<'_>, lint_id: LintId) -> Option<String> {
347
369
None
348
370
}
349
371
372
+ fn is_depreciated_lint ( cx : & LateContext < ' _ > , ty : & hir:: Ty < ' _ > ) -> bool {
373
+ if let hir:: TyKind :: Path ( ref path) = ty. kind {
374
+ if let hir:: def:: Res :: Def ( DefKind :: Struct , def_id) = cx. qpath_res ( path, ty. hir_id ) {
375
+ return match_def_path ( cx, def_id, & DEPRECIATED_LINT_TYPE ) ;
376
+ }
377
+ }
378
+
379
+ false
380
+ }
381
+
350
382
// ==================================================================
351
383
// Lint emission
352
384
// ==================================================================
0 commit comments