about summary refs log tree commit diff
path: root/clippy_dev
diff options
context:
space:
mode:
authorSerial <69764315+Serial-ATA@users.noreply.github.com>2022-06-23 10:37:00 -0400
committerSerial <69764315+Serial-ATA@users.noreply.github.com>2022-06-23 10:44:11 -0400
commitebf77f6d7ecfb2cc60dfb39116d889af76d932cf (patch)
tree5402cbdeb3c22a0fc17c54a88503a1843a0e3e39 /clippy_dev
parent2bd1581bbf8e6e1ac3ad78638ac9c1ab0baa9a8f (diff)
downloadrust-ebf77f6d7ecfb2cc60dfb39116d889af76d932cf.tar.gz
rust-ebf77f6d7ecfb2cc60dfb39116d889af76d932cf.zip
Fix ICE when deprecating lints in directories
Diffstat (limited to 'clippy_dev')
-rw-r--r--clippy_dev/src/update_lints.rs72
1 files changed, 37 insertions, 35 deletions
diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs
index 31deb499b2e..115f5f0064f 100644
--- a/clippy_dev/src/update_lints.rs
+++ b/clippy_dev/src/update_lints.rs
@@ -363,12 +363,12 @@ pub fn deprecate(name: &str, reason: Option<&String>) {
     let name_upper = name.to_uppercase();
 
     let (mut lints, deprecated_lints, renamed_lints) = gather_all();
-    let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { panic!("failed to find lint `{}`", name) };
+    let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { eprintln!("error: failed to find lint `{}`", name); return; };
 
     let mod_path = {
         let mut mod_path = PathBuf::from(format!("clippy_lints/src/{}", lint.module));
         if mod_path.is_dir() {
-            mod_path = mod_path.join(name);
+            mod_path = mod_path.join("mod");
         }
 
         mod_path.set_extension("rs");
@@ -422,7 +422,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
             let mut lint_name_end = impl_lint_pass_start + (lint_name_pos + lint_name_upper.len());
             for c in content[lint_name_end..impl_lint_pass_end].chars() {
                 // Remove trailing whitespace
-                if c.is_whitespace() {
+                if c == ',' || c.is_whitespace() {
                     lint_name_end += 1;
                 } else {
                     break;
@@ -440,39 +440,41 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
                 fs::remove_file(path)?;
             } else {
                 // We can't delete the entire file, just remove the declaration
-                if lint.module != name {
-                    let mut mod_decl_path = path.to_path_buf();
-                    if mod_decl_path.is_dir() {
-                        mod_decl_path = Path::new("clippy_lints/src").join(&lint.module).join("mod.rs");
-                    }
-
-                    let mut content = fs::read_to_string(&mod_decl_path)
-                        .unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
-
-                    eprintln!(
-                        "warn: you will have to manually remove any code related to `{}` from `{}`",
-                        name,
-                        &mod_decl_path.to_string_lossy()
-                    );
-
-                    assert!(
-                        content[lint.declaration_range.clone()].contains(&name.to_uppercase()),
-                        "error: `{}` does not contain lint `{}`'s declaration",
-                        mod_decl_path.display(),
-                        lint.name
-                    );
-
-                    // Remove lint declaration (declare_clippy_lint!)
-                    content.replace_range(lint.declaration_range.clone(), "");
-
-                    // Remove the module declaration (mod xyz;)
-                    let mod_decl = format!("\nmod {};", name);
-                    content = content.replacen(&mod_decl, "", 1);
-
-                    remove_impl_lint_pass(&lint.name.to_uppercase(), &mut content);
-                    fs::write(mod_decl_path, content)
-                        .unwrap_or_else(|_| panic!("failed to write to `{}`", path.to_string_lossy()));
+
+                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");
+
+                    fs::remove_file(lint_mod_path).ok();
                 }
+
+                let mut content =
+                    fs::read_to_string(&path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
+
+                eprintln!(
+                    "warn: you will have to manually remove any code related to `{}` from `{}`",
+                    name,
+                    path.display()
+                );
+
+                assert!(
+                    content[lint.declaration_range.clone()].contains(&name.to_uppercase()),
+                    "error: `{}` does not contain lint `{}`'s declaration",
+                    path.display(),
+                    lint.name
+                );
+
+                // Remove lint declaration (declare_clippy_lint!)
+                content.replace_range(lint.declaration_range.clone(), "");
+
+                // Remove the module declaration (mod xyz;)
+                let mod_decl = format!("\nmod {};", name);
+                content = content.replacen(&mod_decl, "", 1);
+
+                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);