diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 77351233381..656a271aec9 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -72,14 +72,34 @@ pub fn is_internal(&self) -> bool { } } +/// Generates the list of lint links at the bottom of the README pub fn gen_changelog_lint_list(lints: Vec) -> Vec { let mut lint_list_sorted: Vec = lints; lint_list_sorted.sort_by_key(|l| l.name.clone()); lint_list_sorted .iter() - .filter(|l| !l.is_internal()) - .map(|l| { - format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name) + .filter_map(|l| { + if l.is_internal() { + None + } else { + Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name)) + } + }).collect() +} + +/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`. +pub fn gen_deprecated(lints: &[Lint]) -> Vec { + lints.iter() + .filter_map(|l| { + l.clone().deprecation.and_then(|depr_text| { + Some( + format!( + " store.register_removed(\n \"{}\",\n \"{}\",\n );", + l.name, + depr_text + ) + ) + }) }) .collect() } @@ -321,3 +341,18 @@ fn test_gen_changelog_lint_list() { ]; assert_eq!(expected, gen_changelog_lint_list(lints)); } + +#[test] +fn test_gen_deprecated() { + let lints = vec![ + Lint::new("should_assert_eq", "group1", "abc", Some("has been superseeded by should_assert_eq2"), "module_name"), + Lint::new("should_assert_eq2", "group2", "abc", None, "module_name") + ]; + let expected: Vec = vec![ + r#" store.register_removed( + "should_assert_eq", + "has been superseeded by should_assert_eq2", + );"#.to_string() + ]; + assert_eq!(expected, gen_deprecated(&lints)); +} diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 8769ee6b810..887a4ab9328 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -82,4 +82,12 @@ fn update_lints() { false, || { gen_changelog_lint_list(lint_list.clone()) } ); + + replace_region_in_file( + "../clippy_lints/src/lib.rs", + "begin deprecated lints", + "end deprecated lints", + false, + || { gen_deprecated(&lint_list) } + ); } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 207dc40fa1d..86ecba38d59 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -271,6 +271,7 @@ pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf { #[rustfmt::skip] pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { let mut store = reg.sess.lint_store.borrow_mut(); + // begin deprecated lints, do not remove this comment, it’s used in `update_lints` store.register_removed( "should_assert_eq", "`assert!()` will be more flexible with RFC 2011", diff --git a/util/update_lints.py b/util/update_lints.py index 2e1bd98050d..221069d353c 100755 --- a/util/update_lints.py +++ b/util/update_lints.py @@ -240,7 +240,7 @@ def main(print_only=False, check=False): # same for "deprecated" lint collection changed |= replace_region( - 'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints', + 'clippy_lints/src/lib.rs', r'begin deprecated lints', r'end deprecated lints', lambda: gen_deprecated(deprecated_lints), replace_start=False, write_back=not check)