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 ( ) {
@@ -642,6 +660,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
642
660
false
643
661
}
644
662
663
+ fn collect_renames ( lints : & mut Vec < LintMetadata > ) {
664
+ for lint in lints {
665
+ let mut collected = String :: new ( ) ;
666
+ let mut names = vec ! [ lint. id. clone( ) ] ;
667
+
668
+ loop {
669
+ if let Some ( lint_name) = names. pop ( ) {
670
+ for ( k, v) in RENAMED_LINTS {
671
+ if_chain ! {
672
+ if let Some ( name) = v. strip_prefix( CLIPPY_LINT_GROUP_PREFIX ) ;
673
+ if name == lint_name;
674
+ if let Some ( past_name) = k. strip_prefix( CLIPPY_LINT_GROUP_PREFIX ) ;
675
+ then {
676
+ write!( collected, RENAME_VALUE_TEMPLATE !( ) , name = past_name) . unwrap( ) ;
677
+ names. push( past_name. to_string( ) ) ;
678
+ }
679
+ }
680
+ }
681
+
682
+ continue ;
683
+ }
684
+
685
+ break ;
686
+ }
687
+
688
+ if !collected. is_empty ( ) {
689
+ write ! ( & mut lint. docs, RENAMES_SECTION_TEMPLATE !( ) , names = collected) . unwrap ( ) ;
690
+ }
691
+ }
692
+ }
693
+
645
694
// ==================================================================
646
695
// Lint emission
647
696
// ==================================================================
0 commit comments