Skip to content

Commit 64bd658

Browse files
committed
RIIR update lints: Generate deprecated lints
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.
1 parent e695015 commit 64bd658

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

clippy_dev/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ 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());
@@ -84,6 +85,23 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
8485
.collect()
8586
}
8687

88+
/// Generates the 'register_removed' code in `./clippy_lints/src/lib.rs`.
89+
pub fn gen_deprecated(lints: Vec<Lint>) -> Vec<String> {
90+
lints.iter()
91+
.filter(|l| l.deprecation.is_some())
92+
.map(|l| {
93+
format!(
94+
r#" store.register_removed(
95+
"{}",
96+
"{}",
97+
);"#,
98+
l.name,
99+
l.deprecation.clone().unwrap()
100+
)
101+
})
102+
.collect()
103+
}
104+
87105
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
88106
pub fn gather_all() -> impl Iterator<Item=Lint> {
89107
lint_files().flat_map(|f| gather_from_file(&f))
@@ -321,3 +339,18 @@ fn test_gen_changelog_lint_list() {
321339
];
322340
assert_eq!(expected, gen_changelog_lint_list(lints));
323341
}
342+
343+
#[test]
344+
fn test_gen_deprecated() {
345+
let lints = vec![
346+
Lint::new("should_assert_eq", "group1", "abc", Some("has been superseeded by should_assert_eq2"), "module_name"),
347+
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")
348+
];
349+
let expected: Vec<String> = vec![
350+
r#" store.register_removed(
351+
"should_assert_eq",
352+
"has been superseeded by should_assert_eq2",
353+
);"#.to_string()
354+
];
355+
assert_eq!(expected, gen_deprecated(lints));
356+
}

clippy_dev/src/main.rs

Lines changed: 8 additions & 0 deletions
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.clone()) }
92+
);
8593
}

clippy_lints/src/lib.rs

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

util/update_lints.py

Lines changed: 1 addition & 1 deletion
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)