about summary refs log tree commit diff
path: root/clippy_dev/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-02 06:29:40 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-02 06:29:40 +0000
commit0ad5b9b9e08e84f80a4baccd11209553f1e64b2a (patch)
tree1823351293db1e96b4b4be3fc53995c14c344ee2 /clippy_dev/src
parent5172271e70173122bde3018ba455dfa97850c7f6 (diff)
parent7e027217f113b2feafd39b0d19500aa030f320d7 (diff)
downloadrust-0ad5b9b9e08e84f80a4baccd11209553f1e64b2a.tar.gz
rust-0ad5b9b9e08e84f80a4baccd11209553f1e64b2a.zip
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 <dev@phansch.net>
Diffstat (limited to 'clippy_dev/src')
-rw-r--r--clippy_dev/src/lib.rs41
-rw-r--r--clippy_dev/src/main.rs8
2 files changed, 46 insertions, 3 deletions
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 @@ impl Lint {
     }
 }
 
+/// Generates the list of lint links at the bottom of the README
 pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
     let mut lint_list_sorted: Vec<Lint> = 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<String> {
+    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<String> = 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) }
+    );
 }