77//! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such
88//! a simple mistake)
99
10+ use crate :: renamed_lints:: RENAMED_LINTS ;
1011use crate :: utils:: internal_lints:: { extract_clippy_version_value, is_lint_ref_type} ;
1112
1213use clippy_utils:: diagnostics:: span_lint;
@@ -26,6 +27,7 @@ use rustc_span::{sym, Loc, Span, Symbol};
2627use serde:: { ser:: SerializeStruct , Serialize , Serializer } ;
2728use std:: collections:: BinaryHeap ;
2829use std:: fmt;
30+ use std:: fmt:: Write as _;
2931use std:: fs:: { self , OpenOptions } ;
3032use std:: io:: prelude:: * ;
3133use std:: path:: Path ;
@@ -85,6 +87,21 @@ macro_rules! CONFIGURATION_VALUE_TEMPLATE {
8587 } ;
8688}
8789
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+
88105const LINT_EMISSION_FUNCTIONS : [ & [ & str ] ; 8 ] = [
89106 & [ "clippy_utils" , "diagnostics" , "span_lint" ] ,
90107 & [ "clippy_utils" , "diagnostics" , "span_lint_and_help" ] ,
@@ -198,9 +215,10 @@ impl Drop for MetadataCollector {
198215
199216 // Mapping the final data
200217 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+ }
204222
205223 // Outputting
206224 if Path :: new ( OUTPUT_FILE ) . exists ( ) {
@@ -642,6 +660,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
642660 false
643661}
644662
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+
645694// ==================================================================
646695// Lint emission
647696// ==================================================================
0 commit comments