Skip to content

Commit 2a383ae

Browse files
committed
Collect renamed lints
1 parent 6f8d18f commit 2a383ae

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! a simple mistake)
99
1010
use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type};
11+
use crate::renamed_lints::RENAMED_LINTS;
1112

1213
use clippy_utils::diagnostics::span_lint;
1314
use clippy_utils::ty::{match_type, walk_ptrs_ty_depth};
@@ -200,7 +201,10 @@ impl Drop for MetadataCollector {
200201
let mut lints = std::mem::take(&mut self.lints).into_sorted_vec();
201202
lints
202203
.iter_mut()
203-
.for_each(|x| x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default()));
204+
.for_each(|x| {
205+
x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default());
206+
x.past_names = collect_renames(&x.id);
207+
});
204208

205209
// Outputting
206210
if Path::new(OUTPUT_FILE).exists() {
@@ -222,6 +226,7 @@ struct LintMetadata {
222226
/// This field is only used in the output and will only be
223227
/// mapped shortly before the actual output.
224228
applicability: Option<ApplicabilityInfo>,
229+
past_names: Option<Vec<String>>,
225230
}
226231

227232
impl LintMetadata {
@@ -241,6 +246,7 @@ impl LintMetadata {
241246
version,
242247
docs,
243248
applicability: None,
249+
past_names: None,
244250
}
245251
}
246252
}
@@ -643,6 +649,27 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
643649
false
644650
}
645651

652+
fn collect_renames(lint_name: &str) -> Option<Vec<String>> {
653+
let collected = RENAMED_LINTS.iter().filter_map(|(k, v)| {
654+
if_chain! {
655+
if let Some(name) = v.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
656+
if name == lint_name;
657+
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
658+
then {
659+
Some(past_name.to_string())
660+
} else {
661+
None
662+
}
663+
}
664+
}).collect::<Vec<_>>();
665+
666+
if collected.is_empty() {
667+
None
668+
} else {
669+
Some(collected)
670+
}
671+
}
672+
646673
// ==================================================================
647674
// Lint emission
648675
// ==================================================================

0 commit comments

Comments
 (0)