about summary refs log tree commit diff
path: root/src/tools/clippy/clippy_dev
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2025-04-22 16:10:59 +0200
committerPhilipp Krones <hello@philkrones.com>2025-04-22 18:24:43 +0200
commit52bb2bb4610e707757cfe30daa7e8a7b06563679 (patch)
treead9a310c3ca76c60835810470a649dd0cf6aa67a /src/tools/clippy/clippy_dev
parent8bf5a8d12feea10dfada53fb2d119283b0e0107c (diff)
parent0621446356e20fd2ead13a6763bb936c95eb0cfa (diff)
downloadrust-52bb2bb4610e707757cfe30daa7e8a7b06563679.tar.gz
rust-52bb2bb4610e707757cfe30daa7e8a7b06563679.zip
Merge commit '0621446356e20fd2ead13a6763bb936c95eb0cfa' into clippy-subtree-update
Diffstat (limited to 'src/tools/clippy/clippy_dev')
-rw-r--r--src/tools/clippy/clippy_dev/src/lib.rs1
-rw-r--r--src/tools/clippy/clippy_dev/src/main.rs3
-rw-r--r--src/tools/clippy/clippy_dev/src/setup/toolchain.rs2
-rw-r--r--src/tools/clippy/clippy_dev/src/sync.rs2
-rw-r--r--src/tools/clippy/clippy_dev/src/update_lints.rs171
-rw-r--r--src/tools/clippy/clippy_dev/src/utils.rs8
6 files changed, 63 insertions, 124 deletions
diff --git a/src/tools/clippy/clippy_dev/src/lib.rs b/src/tools/clippy/clippy_dev/src/lib.rs
index 9280369c23b..c1ffaf269c6 100644
--- a/src/tools/clippy/clippy_dev/src/lib.rs
+++ b/src/tools/clippy/clippy_dev/src/lib.rs
@@ -13,6 +13,7 @@
 #[allow(unused_extern_crates)]
 extern crate rustc_driver;
 extern crate rustc_lexer;
+extern crate rustc_literal_escaper;
 
 pub mod dogfood;
 pub mod fmt;
diff --git a/src/tools/clippy/clippy_dev/src/main.rs b/src/tools/clippy/clippy_dev/src/main.rs
index 074dea4ab77..83f8e66b334 100644
--- a/src/tools/clippy/clippy_dev/src/main.rs
+++ b/src/tools/clippy/clippy_dev/src/main.rs
@@ -170,7 +170,6 @@ enum DevCommand {
                 "restriction",
                 "cargo",
                 "nursery",
-                "internal",
             ],
             default_value = "nursery",
         )]
@@ -334,7 +333,7 @@ struct SyncCommand {
 #[derive(Subcommand)]
 enum SyncSubcommand {
     #[command(name = "update_nightly")]
-    /// Update nightly version in rust-toolchain and `clippy_utils`
+    /// Update nightly version in `rust-toolchain.toml` and `clippy_utils`
     UpdateNightly,
 }
 
diff --git a/src/tools/clippy/clippy_dev/src/setup/toolchain.rs b/src/tools/clippy/clippy_dev/src/setup/toolchain.rs
index 2966629cf70..ecd80215f7e 100644
--- a/src/tools/clippy/clippy_dev/src/setup/toolchain.rs
+++ b/src/tools/clippy/clippy_dev/src/setup/toolchain.rs
@@ -62,7 +62,7 @@ pub fn create(standalone: bool, force: bool, release: bool, name: &str) {
 
     println!("Created toolchain {name}, use it in other projects with e.g. `cargo +{name} clippy`");
     if !standalone {
-        println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes");
+        println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain.toml` changes");
     }
 }
 
diff --git a/src/tools/clippy/clippy_dev/src/sync.rs b/src/tools/clippy/clippy_dev/src/sync.rs
index 3522d182e90..a6b65e561c2 100644
--- a/src/tools/clippy/clippy_dev/src/sync.rs
+++ b/src/tools/clippy/clippy_dev/src/sync.rs
@@ -10,7 +10,7 @@ pub fn update_nightly() {
     let date = Utc::now().format("%Y-%m-%d").to_string();
     replace_region_in_file(
         UpdateMode::Change,
-        Path::new("rust-toolchain"),
+        Path::new("rust-toolchain.toml"),
         "# begin autogenerated nightly\n",
         "# end autogenerated nightly",
         |res| {
diff --git a/src/tools/clippy/clippy_dev/src/update_lints.rs b/src/tools/clippy/clippy_dev/src/update_lints.rs
index b80ee5aac7e..d848a97f86d 100644
--- a/src/tools/clippy/clippy_dev/src/update_lints.rs
+++ b/src/tools/clippy/clippy_dev/src/update_lints.rs
@@ -1,7 +1,8 @@
 use crate::utils::{UpdateMode, clippy_project_root, exit_with_failure, replace_region_in_file};
 use aho_corasick::AhoCorasickBuilder;
 use itertools::Itertools;
-use rustc_lexer::{LiteralKind, TokenKind, tokenize, unescape};
+use rustc_lexer::{LiteralKind, TokenKind, tokenize};
+use rustc_literal_escaper::{Mode, unescape_unicode};
 use std::collections::{HashMap, HashSet};
 use std::ffi::OsStr;
 use std::fmt::{self, Write};
@@ -37,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,
@@ -47,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();
         },
     );
 
@@ -57,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();
         },
     );
 
@@ -67,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::")))
@@ -86,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();
             }
         },
@@ -95,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);
@@ -106,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}");
@@ -121,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.
@@ -402,53 +401,53 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
         }
     }
 
-    if path.exists() {
-        if let Some(lint) = lints.iter().find(|l| l.name == name) {
-            if lint.module == name {
-                // The lint name is the same as the file, we can just delete the entire file
-                fs::remove_file(path)?;
-            } else {
-                // We can't delete the entire file, just remove the declaration
-
-                if let Some(Some("mod.rs")) = path.file_name().map(OsStr::to_str) {
-                    // Remove clippy_lints/src/some_mod/some_lint.rs
-                    let mut lint_mod_path = path.to_path_buf();
-                    lint_mod_path.set_file_name(name);
-                    lint_mod_path.set_extension("rs");
+    if path.exists()
+        && let Some(lint) = lints.iter().find(|l| l.name == name)
+    {
+        if lint.module == name {
+            // The lint name is the same as the file, we can just delete the entire file
+            fs::remove_file(path)?;
+        } else {
+            // We can't delete the entire file, just remove the declaration
 
-                    let _ = fs::remove_file(lint_mod_path);
-                }
+            if let Some(Some("mod.rs")) = path.file_name().map(OsStr::to_str) {
+                // Remove clippy_lints/src/some_mod/some_lint.rs
+                let mut lint_mod_path = path.to_path_buf();
+                lint_mod_path.set_file_name(name);
+                lint_mod_path.set_extension("rs");
 
-                let mut content =
-                    fs::read_to_string(path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
+                let _ = fs::remove_file(lint_mod_path);
+            }
 
-                eprintln!(
-                    "warn: you will have to manually remove any code related to `{name}` from `{}`",
-                    path.display()
-                );
+            let mut content =
+                fs::read_to_string(path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
 
-                assert!(
-                    content[lint.declaration_range.clone()].contains(&name.to_uppercase()),
-                    "error: `{}` does not contain lint `{}`'s declaration",
-                    path.display(),
-                    lint.name
-                );
+            eprintln!(
+                "warn: you will have to manually remove any code related to `{name}` from `{}`",
+                path.display()
+            );
 
-                // Remove lint declaration (declare_clippy_lint!)
-                content.replace_range(lint.declaration_range.clone(), "");
+            assert!(
+                content[lint.declaration_range.clone()].contains(&name.to_uppercase()),
+                "error: `{}` does not contain lint `{}`'s declaration",
+                path.display(),
+                lint.name
+            );
 
-                // Remove the module declaration (mod xyz;)
-                let mod_decl = format!("\nmod {name};");
-                content = content.replacen(&mod_decl, "", 1);
+            // Remove lint declaration (declare_clippy_lint!)
+            content.replace_range(lint.declaration_range.clone(), "");
 
-                remove_impl_lint_pass(&lint.name.to_uppercase(), &mut content);
-                fs::write(path, content).unwrap_or_else(|_| panic!("failed to write to `{}`", path.to_string_lossy()));
-            }
+            // Remove the module declaration (mod xyz;)
+            let mod_decl = format!("\nmod {name};");
+            content = content.replacen(&mod_decl, "", 1);
 
-            remove_test_assets(name);
-            remove_lint(name, lints);
-            return Ok(true);
+            remove_impl_lint_pass(&lint.name.to_uppercase(), &mut content);
+            fs::write(path, content).unwrap_or_else(|_| panic!("failed to write to `{}`", path.to_string_lossy()));
         }
+
+        remove_test_assets(name);
+        remove_lint(name, lints);
+        return Ok(true);
     }
 
     Ok(false)
@@ -527,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>> {
@@ -579,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");
@@ -830,7 +804,7 @@ fn remove_line_splices(s: &str) -> String {
         .and_then(|s| s.strip_suffix('"'))
         .unwrap_or_else(|| panic!("expected quoted string, found `{s}`"));
     let mut res = String::with_capacity(s.len());
-    unescape::unescape_unicode(s, unescape::Mode::Str, &mut |range, ch| {
+    unescape_unicode(s, Mode::Str, &mut |range, ch| {
         if ch.is_ok() {
             res.push_str(&s[range]);
         }
@@ -937,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()),
diff --git a/src/tools/clippy/clippy_dev/src/utils.rs b/src/tools/clippy/clippy_dev/src/utils.rs
index b87fcca13b1..206816398f5 100644
--- a/src/tools/clippy/clippy_dev/src/utils.rs
+++ b/src/tools/clippy/clippy_dev/src/utils.rs
@@ -30,10 +30,10 @@ pub fn clippy_project_root() -> PathBuf {
     let current_dir = std::env::current_dir().unwrap();
     for path in current_dir.ancestors() {
         let result = fs::read_to_string(path.join("Cargo.toml"));
-        if let Err(err) = &result {
-            if err.kind() == io::ErrorKind::NotFound {
-                continue;
-            }
+        if let Err(err) = &result
+            && err.kind() == io::ErrorKind::NotFound
+        {
+            continue;
         }
 
         let content = result.unwrap();