about summary refs log tree commit diff
path: root/clippy_dev
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2024-08-05 18:23:48 -0400
committerJason Newcomb <jsnewcomb@pm.me>2025-04-12 17:53:36 -0400
commit5b4b463d4925d2ccc56afbf83a2f0e4a50b0f56c (patch)
tree00ea17151e827168665748508d3b9c2dbd7236f0 /clippy_dev
parentec105bab2f29abe73f55bbf9e9aefcf143e88383 (diff)
downloadrust-5b4b463d4925d2ccc56afbf83a2f0e4a50b0f56c.tar.gz
rust-5b4b463d4925d2ccc56afbf83a2f0e4a50b0f56c.zip
Move internal lints to their own crate
Diffstat (limited to 'clippy_dev')
-rw-r--r--clippy_dev/src/main.rs1
-rw-r--r--clippy_dev/src/update_lints.rs90
2 files changed, 14 insertions, 77 deletions
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index 0380b7e6a6d..83f8e66b334 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -170,7 +170,6 @@ enum DevCommand {
                 "restriction",
                 "cargo",
                 "nursery",
-                "internal",
             ],
             default_value = "nursery",
         )]
diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs
index 0be24f322d2..90683a23544 100644
--- a/clippy_dev/src/update_lints.rs
+++ b/clippy_dev/src/update_lints.rs
@@ -37,9 +37,8 @@ fn generate_lint_files(
     deprecated_lints: &[DeprecatedLint],
     renamed_lints: &[RenamedLint],
 ) {
-    let internal_lints = Lint::internal_lints(lints);
-    let mut usable_lints = Lint::usable_lints(lints);
-    usable_lints.sort_by_key(|lint| lint.name.clone());
+    let mut lints = lints.to_owned();
+    lints.sort_by_key(|lint| lint.name.clone());
 
     replace_region_in_file(
         update_mode,
@@ -47,7 +46,7 @@ fn generate_lint_files(
         "[There are over ",
         " lints included in this crate!]",
         |res| {
-            write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
+            write!(res, "{}", round_to_fifty(lints.len())).unwrap();
         },
     );
 
@@ -57,7 +56,7 @@ fn generate_lint_files(
         "[There are over ",
         " lints included in this crate!]",
         |res| {
-            write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
+            write!(res, "{}", round_to_fifty(lints.len())).unwrap();
         },
     );
 
@@ -67,7 +66,7 @@ fn generate_lint_files(
         "<!-- begin autogenerated links to lint list -->\n",
         "<!-- end autogenerated links to lint list -->",
         |res| {
-            for lint in usable_lints
+            for lint in lints
                 .iter()
                 .map(|l| &*l.name)
                 .chain(deprecated_lints.iter().filter_map(|l| l.name.strip_prefix("clippy::")))
@@ -86,7 +85,7 @@ fn generate_lint_files(
         "// begin lints modules, do not remove this comment, it’s used in `update_lints`\n",
         "// end lints modules, do not remove this comment, it’s used in `update_lints`",
         |res| {
-            for lint_mod in usable_lints.iter().map(|l| &l.module).unique().sorted() {
+            for lint_mod in lints.iter().map(|l| &l.module).unique().sorted() {
                 writeln!(res, "mod {lint_mod};").unwrap();
             }
         },
@@ -95,7 +94,7 @@ fn generate_lint_files(
     process_file(
         "clippy_lints/src/declared_lints.rs",
         update_mode,
-        &gen_declared_lints(internal_lints.iter(), usable_lints.iter()),
+        &gen_declared_lints(lints.iter()),
     );
 
     let content = gen_deprecated_lints_test(deprecated_lints);
@@ -106,10 +105,9 @@ fn generate_lint_files(
 }
 
 pub fn print_lints() {
-    let (lint_list, _, _) = gather_all();
-    let usable_lints = Lint::usable_lints(&lint_list);
-    let usable_lint_count = usable_lints.len();
-    let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
+    let (lints, _, _) = gather_all();
+    let lint_count = lints.len();
+    let grouped_by_lint_group = Lint::by_lint_group(lints.into_iter());
 
     for (lint_group, mut lints) in grouped_by_lint_group {
         println!("\n## {lint_group}");
@@ -121,7 +119,7 @@ pub fn print_lints() {
         }
     }
 
-    println!("there are {usable_lint_count} lints");
+    println!("there are {lint_count} lints");
 }
 
 /// Runs the `rename_lint` command.
@@ -527,22 +525,6 @@ impl Lint {
         }
     }
 
-    /// Returns all non-deprecated lints and non-internal lints
-    #[must_use]
-    fn usable_lints(lints: &[Self]) -> Vec<Self> {
-        lints
-            .iter()
-            .filter(|l| !l.group.starts_with("internal"))
-            .cloned()
-            .collect()
-    }
-
-    /// Returns all internal lints
-    #[must_use]
-    fn internal_lints(lints: &[Self]) -> Vec<Self> {
-        lints.iter().filter(|l| l.group == "internal").cloned().collect()
-    }
-
     /// Returns the lints in a `HashMap`, grouped by the different lint groups
     #[must_use]
     fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
@@ -579,23 +561,14 @@ impl RenamedLint {
 
 /// Generates the code for registering lints
 #[must_use]
-fn gen_declared_lints<'a>(
-    internal_lints: impl Iterator<Item = &'a Lint>,
-    usable_lints: impl Iterator<Item = &'a Lint>,
-) -> String {
-    let mut details: Vec<_> = internal_lints
-        .map(|l| (false, &l.module, l.name.to_uppercase()))
-        .chain(usable_lints.map(|l| (true, &l.module, l.name.to_uppercase())))
-        .collect();
+fn gen_declared_lints<'a>(lints: impl Iterator<Item = &'a Lint>) -> String {
+    let mut details: Vec<_> = lints.map(|l| (&l.module, l.name.to_uppercase())).collect();
     details.sort_unstable();
 
     let mut output = GENERATED_FILE_COMMENT.to_string();
     output.push_str("pub static LINTS: &[&crate::LintInfo] = &[\n");
 
-    for (is_public, module_name, lint_name) in details {
-        if !is_public {
-            output.push_str("    #[cfg(feature = \"internal\")]\n");
-        }
+    for (module_name, lint_name) in details {
         let _: fmt::Result = writeln!(output, "    crate::{module_name}::{lint_name}_INFO,");
     }
     output.push_str("];\n");
@@ -937,41 +910,6 @@ mod tests {
     }
 
     #[test]
-    fn test_usable_lints() {
-        let lints = vec![
-            Lint::new(
-                "should_assert_eq2",
-                "Not Deprecated",
-                "\"abc\"",
-                "module_name",
-                Range::default(),
-            ),
-            Lint::new(
-                "should_assert_eq2",
-                "internal",
-                "\"abc\"",
-                "module_name",
-                Range::default(),
-            ),
-            Lint::new(
-                "should_assert_eq2",
-                "internal_style",
-                "\"abc\"",
-                "module_name",
-                Range::default(),
-            ),
-        ];
-        let expected = vec![Lint::new(
-            "should_assert_eq2",
-            "Not Deprecated",
-            "\"abc\"",
-            "module_name",
-            Range::default(),
-        )];
-        assert_eq!(expected, Lint::usable_lints(&lints));
-    }
-
-    #[test]
     fn test_by_lint_group() {
         let lints = vec![
             Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),