From 64bd658516d6a097c04295a3f90537d757c258bd Mon Sep 17 00:00:00 2001
From: Philipp Hansch <dev@phansch.net>
Date: Wed, 31 Oct 2018 08:03:50 +0100
Subject: [PATCH 1/2] 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.
---
 clippy_dev/src/lib.rs   | 33 +++++++++++++++++++++++++++++++++
 clippy_dev/src/main.rs  |  8 ++++++++
 clippy_lints/src/lib.rs |  1 +
 util/update_lints.py    |  2 +-
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index 773512333815..d2191d426ffe 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -72,6 +72,7 @@ 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());
@@ -84,6 +85,23 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
         .collect()
 }
 
+/// Generates the 'register_removed' code in `./clippy_lints/src/lib.rs`.
+pub fn gen_deprecated(lints: Vec<Lint>) -> Vec<String> {
+    lints.iter()
+        .filter(|l| l.deprecation.is_some())
+        .map(|l| {
+            format!(
+                r#"    store.register_removed(
+        "{}",
+        "{}",
+    );"#,
+                l.name,
+                l.deprecation.clone().unwrap()
+            )
+        })
+        .collect()
+}
+
 /// Gathers all files in `src/clippy_lints` and gathers all lints inside
 pub fn gather_all() -> impl Iterator<Item=Lint> {
     lint_files().flat_map(|f| gather_from_file(&f))
@@ -321,3 +339,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 8769ee6b8103..cf321dbbc020 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.clone()) }
+    );
 }
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index eaff87e78f8b..f7b103e8d724 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -270,6 +270,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 2e1bd98050d0..221069d353cb 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)

From 7e027217f113b2feafd39b0d19500aa030f320d7 Mon Sep 17 00:00:00 2001
From: Philipp Hansch <dev@phansch.net>
Date: Wed, 31 Oct 2018 21:54:30 +0100
Subject: [PATCH 2/2] Fix dogfood and pedantic lints

---
 clippy_dev/src/lib.rs  | 38 ++++++++++++++++++++------------------
 clippy_dev/src/main.rs |  2 +-
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index d2191d426ffe..656a271aec99 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -78,26 +78,28 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
     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)
-        })
-        .collect()
+        .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: Vec<Lint>) -> Vec<String> {
+/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
+pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
     lints.iter()
-        .filter(|l| l.deprecation.is_some())
-        .map(|l| {
-            format!(
-                r#"    store.register_removed(
-        "{}",
-        "{}",
-    );"#,
-                l.name,
-                l.deprecation.clone().unwrap()
-            )
+        .filter_map(|l| {
+            l.clone().deprecation.and_then(|depr_text| {
+                Some(
+                    format!(
+                        "    store.register_removed(\n        \"{}\",\n        \"{}\",\n    );",
+                        l.name,
+                        depr_text
+                    )
+                )
+            })
         })
         .collect()
 }
@@ -352,5 +354,5 @@ fn test_gen_deprecated() {
         "has been superseeded by should_assert_eq2",
     );"#.to_string()
     ];
-    assert_eq!(expected, gen_deprecated(lints));
+    assert_eq!(expected, gen_deprecated(&lints));
 }
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index cf321dbbc020..887a4ab93289 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -88,6 +88,6 @@ fn update_lints() {
         "begin deprecated lints",
         "end deprecated lints",
         false,
-        || { gen_deprecated(lint_list.clone()) }
+        || { gen_deprecated(&lint_list) }
     );
 }