Skip to content

Commit 0db5e6b

Browse files
committed
Collect renamed lints
1 parent 6f8d18f commit 0db5e6b

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 54 additions & 3 deletions
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() {
@@ -222,6 +240,7 @@ struct LintMetadata {
222240
/// This field is only used in the output and will only be
223241
/// mapped shortly before the actual output.
224242
applicability: Option<ApplicabilityInfo>,
243+
past_names: Option<Vec<String>>,
225244
}
226245

227246
impl LintMetadata {
@@ -241,6 +260,7 @@ impl LintMetadata {
241260
version,
242261
docs,
243262
applicability: None,
263+
past_names: None,
244264
}
245265
}
246266
}
@@ -643,6 +663,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
643663
false
644664
}
645665

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+
646697
// ==================================================================
647698
// Lint emission
648699
// ==================================================================

0 commit comments

Comments
 (0)