mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 21:53:23 +00:00
Collect renamed lints
This commit is contained in:
parent
6f8d18fe69
commit
45be175eeb
1 changed files with 52 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
||||||
//! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such
|
//! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such
|
||||||
//! a simple mistake)
|
//! a simple mistake)
|
||||||
|
|
||||||
|
use crate::renamed_lints::RENAMED_LINTS;
|
||||||
use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type};
|
use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type};
|
||||||
|
|
||||||
use clippy_utils::diagnostics::span_lint;
|
use clippy_utils::diagnostics::span_lint;
|
||||||
|
@ -26,6 +27,7 @@ use rustc_span::{sym, Loc, Span, Symbol};
|
||||||
use serde::{ser::SerializeStruct, Serialize, Serializer};
|
use serde::{ser::SerializeStruct, Serialize, Serializer};
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fmt::Write as _;
|
||||||
use std::fs::{self, OpenOptions};
|
use std::fs::{self, OpenOptions};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -85,6 +87,21 @@ macro_rules! CONFIGURATION_VALUE_TEMPLATE {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! RENAMES_SECTION_TEMPLATE {
|
||||||
|
() => {
|
||||||
|
r#"
|
||||||
|
### Past names
|
||||||
|
|
||||||
|
{names}
|
||||||
|
"#
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! RENAME_VALUE_TEMPLATE {
|
||||||
|
() => {
|
||||||
|
"* `{name}`\n"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const LINT_EMISSION_FUNCTIONS: [&[&str]; 8] = [
|
const LINT_EMISSION_FUNCTIONS: [&[&str]; 8] = [
|
||||||
&["clippy_utils", "diagnostics", "span_lint"],
|
&["clippy_utils", "diagnostics", "span_lint"],
|
||||||
&["clippy_utils", "diagnostics", "span_lint_and_help"],
|
&["clippy_utils", "diagnostics", "span_lint_and_help"],
|
||||||
|
@ -198,9 +215,10 @@ impl Drop for MetadataCollector {
|
||||||
|
|
||||||
// Mapping the final data
|
// Mapping the final data
|
||||||
let mut lints = std::mem::take(&mut self.lints).into_sorted_vec();
|
let mut lints = std::mem::take(&mut self.lints).into_sorted_vec();
|
||||||
lints
|
collect_renames(&mut lints);
|
||||||
.iter_mut()
|
for x in &mut lints {
|
||||||
.for_each(|x| x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default()));
|
x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default());
|
||||||
|
}
|
||||||
|
|
||||||
// Outputting
|
// Outputting
|
||||||
if Path::new(OUTPUT_FILE).exists() {
|
if Path::new(OUTPUT_FILE).exists() {
|
||||||
|
@ -643,6 +661,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn collect_renames(lints: &mut Vec<LintMetadata>) {
|
||||||
|
for lint in lints {
|
||||||
|
let mut collected = String::new();
|
||||||
|
let mut names = vec![lint.id.clone()];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if let Some(lint_name) = names.pop() {
|
||||||
|
for (k, v) in RENAMED_LINTS {
|
||||||
|
if_chain! {
|
||||||
|
if let Some(name) = v.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
|
||||||
|
if name == lint_name;
|
||||||
|
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
|
||||||
|
then {
|
||||||
|
write!(collected, RENAME_VALUE_TEMPLATE!(), name = past_name).unwrap();
|
||||||
|
names.push(past_name.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !collected.is_empty() {
|
||||||
|
write!(&mut lint.docs, RENAMES_SECTION_TEMPLATE!(), names = collected).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
// Lint emission
|
// Lint emission
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
|
|
Loading…
Reference in a new issue