about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/utils/internal_lints/metadata_collector.rs37
1 files changed, 10 insertions, 27 deletions
diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs
index f49c3fadb07..c38a3e81b0f 100644
--- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs
+++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs
@@ -31,7 +31,7 @@ use serde::{Serialize, Serializer};
 use std::collections::{BTreeSet, BinaryHeap};
 use std::fmt;
 use std::fmt::Write as _;
-use std::fs::{self, OpenOptions};
+use std::fs::{self, File};
 use std::io::prelude::*;
 use std::path::{Path, PathBuf};
 use std::process::Command;
@@ -229,25 +229,10 @@ impl Drop for MetadataCollector {
         collect_renames(&mut lints);
 
         // Outputting json
-        if Path::new(JSON_OUTPUT_FILE).exists() {
-            fs::remove_file(JSON_OUTPUT_FILE).unwrap();
-        }
-        let mut file = OpenOptions::new()
-            .write(true)
-            .create(true)
-            .open(JSON_OUTPUT_FILE)
-            .unwrap();
-        writeln!(file, "{}", serde_json::to_string_pretty(&lints).unwrap()).unwrap();
+        fs::write(JSON_OUTPUT_FILE, serde_json::to_string_pretty(&lints).unwrap()).unwrap();
 
         // Outputting markdown
-        if Path::new(MARKDOWN_OUTPUT_FILE).exists() {
-            fs::remove_file(MARKDOWN_OUTPUT_FILE).unwrap();
-        }
-        let mut file = OpenOptions::new()
-            .write(true)
-            .create(true)
-            .open(MARKDOWN_OUTPUT_FILE)
-            .unwrap();
+        let mut file = File::create(MARKDOWN_OUTPUT_FILE).unwrap();
         writeln!(
             file,
             "<!--
@@ -261,17 +246,15 @@ Please use that command to update the file and do not edit it by hand.
         .unwrap();
 
         // Write configuration links to CHANGELOG.md
-        let mut changelog = std::fs::read_to_string(CHANGELOG_PATH).unwrap();
-        let mut changelog_file = OpenOptions::new().read(true).write(true).open(CHANGELOG_PATH).unwrap();
-
-        if let Some(position) = changelog.find("<!-- begin autogenerated links to configuration documentation -->") {
-            // I know this is kinda wasteful, we just don't have regex on `clippy_lints` so... this is the best
-            // we can do AFAIK.
-            changelog = changelog[..position].to_string();
-        }
+        let changelog = std::fs::read_to_string(CHANGELOG_PATH).unwrap();
+        let mut changelog_file = File::create(CHANGELOG_PATH).unwrap();
+        let position = changelog
+            .find("<!-- begin autogenerated links to configuration documentation -->")
+            .unwrap();
         writeln!(
             changelog_file,
-            "{changelog}<!-- begin autogenerated links to configuration documentation -->\n{}\n<!-- end autogenerated links to configuration documentation -->",
+            "{}<!-- begin autogenerated links to configuration documentation -->\n{}\n<!-- end autogenerated links to configuration documentation -->",
+            &changelog[..position],
             self.configs_to_markdown(ClippyConfiguration::to_markdown_link)
         )
         .unwrap();