Skip to content

Commit 0ad5b9b

Browse files
bors[bot]phansch
andcommitted
Merge #3388
3388: RIIR update lints: Generate deprecated lints r=phansch a=phansch The update script now also generates the 'register_removed' section in `clippy_lints/src/lib.rs`. Also, instead of using `let mut store ...`, I added a new identifier line so that the replacement will continue to work in case `let mut store ...` ever changes. cc #2882 Co-authored-by: Philipp Hansch <[email protected]>
2 parents 5172271 + 7e02721 commit 0ad5b9b

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

clippy_dev/src/lib.rs

+38-3
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,34 @@ impl Lint {
7272
}
7373
}
7474

75+
/// Generates the list of lint links at the bottom of the README
7576
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
7677
let mut lint_list_sorted: Vec<Lint> = lints;
7778
lint_list_sorted.sort_by_key(|l| l.name.clone());
7879
lint_list_sorted
7980
.iter()
80-
.filter(|l| !l.is_internal())
81-
.map(|l| {
82-
format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name)
81+
.filter_map(|l| {
82+
if l.is_internal() {
83+
None
84+
} else {
85+
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name))
86+
}
87+
}).collect()
88+
}
89+
90+
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
91+
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
92+
lints.iter()
93+
.filter_map(|l| {
94+
l.clone().deprecation.and_then(|depr_text| {
95+
Some(
96+
format!(
97+
" store.register_removed(\n \"{}\",\n \"{}\",\n );",
98+
l.name,
99+
depr_text
100+
)
101+
)
102+
})
83103
})
84104
.collect()
85105
}
@@ -321,3 +341,18 @@ fn test_gen_changelog_lint_list() {
321341
];
322342
assert_eq!(expected, gen_changelog_lint_list(lints));
323343
}
344+
345+
#[test]
346+
fn test_gen_deprecated() {
347+
let lints = vec![
348+
Lint::new("should_assert_eq", "group1", "abc", Some("has been superseeded by should_assert_eq2"), "module_name"),
349+
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")
350+
];
351+
let expected: Vec<String> = vec![
352+
r#" store.register_removed(
353+
"should_assert_eq",
354+
"has been superseeded by should_assert_eq2",
355+
);"#.to_string()
356+
];
357+
assert_eq!(expected, gen_deprecated(&lints));
358+
}

clippy_dev/src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ fn update_lints() {
8282
false,
8383
|| { gen_changelog_lint_list(lint_list.clone()) }
8484
);
85+
86+
replace_region_in_file(
87+
"../clippy_lints/src/lib.rs",
88+
"begin deprecated lints",
89+
"end deprecated lints",
90+
false,
91+
|| { gen_deprecated(&lint_list) }
92+
);
8593
}

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
271271
#[rustfmt::skip]
272272
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
273273
let mut store = reg.sess.lint_store.borrow_mut();
274+
// begin deprecated lints, do not remove this comment, it’s used in `update_lints`
274275
store.register_removed(
275276
"should_assert_eq",
276277
"`assert!()` will be more flexible with RFC 2011",

util/update_lints.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def main(print_only=False, check=False):
240240

241241
# same for "deprecated" lint collection
242242
changed |= replace_region(
243-
'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints',
243+
'clippy_lints/src/lib.rs', r'begin deprecated lints', r'end deprecated lints',
244244
lambda: gen_deprecated(deprecated_lints),
245245
replace_start=False,
246246
write_back=not check)

0 commit comments

Comments
 (0)