about summary refs log tree commit diff
path: root/clippy_dev
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-04-18 12:04:08 +0000
committerGitHub <noreply@github.com>2025-04-18 12:04:08 +0000
commit781fdab9a95320bf8c3eb092ef628352643059bf (patch)
tree70b47c80f944bd7c8312823d44c15131b5e85235 /clippy_dev
parentbcd76c3384098f1fa7fba69a52e8f0e2555c04a0 (diff)
parent5b4b463d4925d2ccc56afbf83a2f0e4a50b0f56c (diff)
downloadrust-781fdab9a95320bf8c3eb092ef628352643059bf.tar.gz
rust-781fdab9a95320bf8c3eb092ef628352643059bf.zip
Move internal lints to their own crate (#13223)
This makes it so switching the internal feature on/off no longer
rebuilds `clippy_lints`.

r? @flip1995

changelog: none
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 02a432b26da..d848a97f86d 100644
--- a/clippy_dev/src/update_lints.rs
+++ b/clippy_dev/src/update_lints.rs
@@ -38,9 +38,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,
@@ -48,7 +47,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();
         },
     );
 
@@ -58,7 +57,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();
         },
     );
 
@@ -68,7 +67,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::")))
@@ -87,7 +86,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();
             }
         },
@@ -96,7 +95,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);
@@ -107,10 +106,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}");
@@ -122,7 +120,7 @@ pub fn print_lints() {
         }
     }
 
-    println!("there are {usable_lint_count} lints");
+    println!("there are {lint_count} lints");
 }
 
 /// Runs the `rename_lint` command.
@@ -528,22 +526,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>> {
@@ -580,23 +562,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");
@@ -938,41 +911,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()),