@@ -116,6 +116,8 @@ const DEPRECATED_LINT_TYPE: [&str; 3] = ["clippy_lints", "deprecated_lints", "Cl
116
116
const APPLICABILITY_NAME_INDEX : usize = 2 ;
117
117
/// This applicability will be set for unresolved applicability values.
118
118
const APPLICABILITY_UNRESOLVED_STR : & str = "Unresolved" ;
119
+ /// The version that will be displayed if none has been defined
120
+ const VERION_DEFAULT_STR : & str = "Unknown" ;
119
121
120
122
declare_clippy_lint ! {
121
123
/// ### What it does
@@ -144,6 +146,7 @@ declare_clippy_lint! {
144
146
/// "docs": " ### What it does\nCollects metadata about clippy lints for the website. [...] "
145
147
/// }
146
148
/// ```
149
+ #[ clippy:: version = "0.1.56" ]
147
150
pub INTERNAL_METADATA_COLLECTOR ,
148
151
internal_warn,
149
152
"A busy bee collection metadata about lints"
@@ -215,18 +218,27 @@ struct LintMetadata {
215
218
group : String ,
216
219
level : String ,
217
220
docs : String ,
221
+ version : String ,
218
222
/// This field is only used in the output and will only be
219
223
/// mapped shortly before the actual output.
220
224
applicability : Option < ApplicabilityInfo > ,
221
225
}
222
226
223
227
impl LintMetadata {
224
- fn new ( id : String , id_span : SerializableSpan , group : String , level : & ' static str , docs : String ) -> Self {
228
+ fn new (
229
+ id : String ,
230
+ id_span : SerializableSpan ,
231
+ group : String ,
232
+ level : & ' static str ,
233
+ version : String ,
234
+ docs : String ,
235
+ ) -> Self {
225
236
Self {
226
237
id,
227
238
id_span,
228
239
group,
229
240
level : level. to_string ( ) ,
241
+ version,
230
242
docs,
231
243
applicability : None ,
232
244
}
@@ -410,12 +422,14 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
410
422
if let Some ( configuration_section) = self . get_lint_configs( & lint_name) {
411
423
docs. push_str( & configuration_section) ;
412
424
}
425
+ let version = get_lint_version( cx, item) ;
413
426
414
427
self . lints. push( LintMetadata :: new(
415
428
lint_name,
416
429
SerializableSpan :: from_item( cx, item) ,
417
430
group,
418
431
level,
432
+ version,
419
433
docs,
420
434
) ) ;
421
435
}
@@ -429,11 +443,14 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
429
443
// Metadata the little we can get from a deprecated lint
430
444
if let Some ( docs) = extract_attr_docs_or_lint( cx, item) ;
431
445
then {
446
+ let version = get_lint_version( cx, item) ;
447
+
432
448
self . lints. push( LintMetadata :: new(
433
449
lint_name,
434
450
SerializableSpan :: from_item( cx, item) ,
435
451
DEPRECATED_LINT_GROUP_STR . to_string( ) ,
436
452
DEPRECATED_LINT_LEVEL ,
453
+ version,
437
454
docs,
438
455
) ) ;
439
456
}
@@ -541,6 +558,28 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
541
558
Some ( docs)
542
559
}
543
560
561
+ fn get_lint_version ( cx : & LateContext < ' _ > , item : & Item < ' _ > ) -> String {
562
+ let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
563
+ attrs
564
+ . iter ( )
565
+ . find_map ( |attr| {
566
+ if_chain ! {
567
+ // Identify attribute
568
+ if let ast:: AttrKind :: Normal ( ref attr_kind, _) = & attr. kind;
569
+ if let [ tool_name, attr_name] = & attr_kind. path. segments[ ..] ;
570
+ if tool_name. ident. name == sym:: clippy;
571
+ if attr_name. ident. name == sym:: version;
572
+ if let Some ( version) = attr. value_str( ) ;
573
+ then {
574
+ Some ( version. as_str( ) . to_string( ) )
575
+ } else {
576
+ None
577
+ }
578
+ }
579
+ } )
580
+ . unwrap_or_else ( || VERION_DEFAULT_STR . to_string ( ) )
581
+ }
582
+
544
583
fn get_lint_group_and_level_or_lint (
545
584
cx : & LateContext < ' _ > ,
546
585
lint_name : & str ,
@@ -652,7 +691,6 @@ fn extract_emission_info<'hir>(
652
691
applicability = resolve_applicability ( cx, arg) ;
653
692
} else if arg_ty. is_closure ( ) {
654
693
multi_part |= check_is_multi_part ( cx, arg) ;
655
- // TODO xFrednet 2021-03-01: don't use or_else but rather a comparison
656
694
applicability = applicability. or_else ( || resolve_applicability ( cx, arg) ) ;
657
695
}
658
696
}
0 commit comments