7
7
//! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such
8
8
//! a simple mistake)
9
9
10
+ use crate :: renamed_lints:: RENAMED_LINTS ;
10
11
use crate :: utils:: internal_lints:: { extract_clippy_version_value, is_lint_ref_type} ;
11
12
12
13
use clippy_utils:: diagnostics:: span_lint;
@@ -26,6 +27,7 @@ use rustc_span::{sym, Loc, Span, Symbol};
26
27
use serde:: { ser:: SerializeStruct , Serialize , Serializer } ;
27
28
use std:: collections:: BinaryHeap ;
28
29
use std:: fmt;
30
+ use std:: fmt:: Write as _;
29
31
use std:: fs:: { self , OpenOptions } ;
30
32
use std:: io:: prelude:: * ;
31
33
use std:: path:: Path ;
@@ -85,6 +87,21 @@ macro_rules! CONFIGURATION_VALUE_TEMPLATE {
85
87
} ;
86
88
}
87
89
90
+ macro_rules! RENAMES_SECTION_TEMPLATE {
91
+ ( ) => {
92
+ r#"
93
+ ### Past names
94
+
95
+ {names}
96
+ "#
97
+ } ;
98
+ }
99
+ macro_rules! RENAME_VALUE_TEMPLATE {
100
+ ( ) => {
101
+ "* `{name}`\n "
102
+ } ;
103
+ }
104
+
88
105
const LINT_EMISSION_FUNCTIONS : [ & [ & str ] ; 8 ] = [
89
106
& [ "clippy_utils" , "diagnostics" , "span_lint" ] ,
90
107
& [ "clippy_utils" , "diagnostics" , "span_lint_and_help" ] ,
@@ -198,9 +215,10 @@ impl Drop for MetadataCollector {
198
215
199
216
// Mapping the final data
200
217
let mut lints = std:: mem:: take ( & mut self . lints ) . into_sorted_vec ( ) ;
201
- lints
202
- . iter_mut ( )
203
- . for_each ( |x| x. applicability = Some ( applicability_info. remove ( & x. id ) . unwrap_or_default ( ) ) ) ;
218
+ collect_renames ( & mut lints) ;
219
+ for x in & mut lints {
220
+ x. applicability = Some ( applicability_info. remove ( & x. id ) . unwrap_or_default ( ) ) ;
221
+ }
204
222
205
223
// Outputting
206
224
if Path :: new ( OUTPUT_FILE ) . exists ( ) {
@@ -222,6 +240,7 @@ struct LintMetadata {
222
240
/// This field is only used in the output and will only be
223
241
/// mapped shortly before the actual output.
224
242
applicability : Option < ApplicabilityInfo > ,
243
+ past_names : Option < Vec < String > > ,
225
244
}
226
245
227
246
impl LintMetadata {
@@ -241,6 +260,7 @@ impl LintMetadata {
241
260
version,
242
261
docs,
243
262
applicability : None ,
263
+ past_names : None ,
244
264
}
245
265
}
246
266
}
@@ -643,6 +663,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
643
663
false
644
664
}
645
665
666
+ fn collect_renames ( lints : & mut Vec < LintMetadata > ) {
667
+ for lint in lints {
668
+ let mut collected = String :: new ( ) ;
669
+ let mut names = vec ! [ lint. id. clone( ) ] ;
670
+
671
+ loop {
672
+ if let Some ( lint_name) = names. pop ( ) {
673
+ for ( k, v) in RENAMED_LINTS {
674
+ if_chain ! {
675
+ if let Some ( name) = v. strip_prefix( CLIPPY_LINT_GROUP_PREFIX ) ;
676
+ if name == lint_name;
677
+ if let Some ( past_name) = k. strip_prefix( CLIPPY_LINT_GROUP_PREFIX ) ;
678
+ then {
679
+ write!( collected, RENAME_VALUE_TEMPLATE !( ) , name = past_name) . unwrap( ) ;
680
+ names. push( past_name. to_string( ) ) ;
681
+ }
682
+ }
683
+ }
684
+
685
+ continue ;
686
+ }
687
+
688
+ break ;
689
+ }
690
+
691
+ if !collected. is_empty ( ) {
692
+ write ! ( & mut lint. docs, RENAMES_SECTION_TEMPLATE !( ) , names = collected) . unwrap ( ) ;
693
+ }
694
+ }
695
+ }
696
+
646
697
// ==================================================================
647
698
// Lint emission
648
699
// ==================================================================
0 commit comments