Skip to content

Commit 45be175

Browse files
committed
Collect renamed lints
1 parent 6f8d18f commit 45be175

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+52-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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;
1011
use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type};
1112

1213
use clippy_utils::diagnostics::span_lint;
@@ -26,6 +27,7 @@ use rustc_span::{sym, Loc, Span, Symbol};
2627
use serde::{ser::SerializeStruct, Serialize, Serializer};
2728
use std::collections::BinaryHeap;
2829
use std::fmt;
30+
use std::fmt::Write as _;
2931
use std::fs::{self, OpenOptions};
3032
use std::io::prelude::*;
3133
use 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+
88105
const 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() {
@@ -643,6 +661,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
643661
false
644662
}
645663

664+
fn collect_renames(lints: &mut Vec<LintMetadata>) {
665+
for lint in lints {
666+
let mut collected = String::new();
667+
let mut names = vec![lint.id.clone()];
668+
669+
loop {
670+
if let Some(lint_name) = names.pop() {
671+
for (k, v) in RENAMED_LINTS {
672+
if_chain! {
673+
if let Some(name) = v.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
674+
if name == lint_name;
675+
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
676+
then {
677+
write!(collected, RENAME_VALUE_TEMPLATE!(), name = past_name).unwrap();
678+
names.push(past_name.to_string());
679+
}
680+
}
681+
}
682+
683+
continue;
684+
}
685+
686+
break;
687+
}
688+
689+
if !collected.is_empty() {
690+
write!(&mut lint.docs, RENAMES_SECTION_TEMPLATE!(), names = collected).unwrap();
691+
}
692+
}
693+
}
694+
646695
// ==================================================================
647696
// Lint emission
648697
// ==================================================================

0 commit comments

Comments
 (0)