]> git.lizzy.rs Git - rust.git/blobdiff - src/filemap.rs
Cargo clippy
[rust.git] / src / filemap.rs
index 72724da1c1189b031ecde43ed68c2b8e48e938cf..c7fa5e2f1efddcbbbffa125205cedd11e6b00ab5 100644 (file)
@@ -8,14 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
 // TODO: add tests
 
 use std::fs::{self, File};
 use std::io::{self, BufWriter, Read, Write};
 
-use strings::string_buffer::StringBuffer;
-
 use checkstyle::{output_checkstyle_file, output_footer, output_header};
 use config::{Config, NewlineStyle, WriteMode};
 use rustfmt_diff::{make_diff, print_diff, Mismatch};
 // A map of the files of a crate, with their new content
 pub type FileMap = Vec<FileRecord>;
 
-pub type FileRecord = (String, StringBuffer);
+pub type FileRecord = (String, String);
 
 // Append a newline to the end of each file.
-pub fn append_newline(s: &mut StringBuffer) {
+pub fn append_newline(s: &mut String) {
     s.push_str("\n");
 }
 
-pub fn write_all_files<T>(file_map: &FileMap, out: &mut T, config: &Config) -> Result<(), io::Error>
+pub fn write_all_files<T>(
+    file_map: &[FileRecord],
+    out: &mut T,
+    config: &Config,
+) -> Result<(), io::Error>
 where
     T: Write,
 {
@@ -44,11 +45,7 @@ pub fn write_all_files<T>(file_map: &FileMap, out: &mut T, config: &Config) -> R
 }
 
 // Prints all newlines either as `\n` or as `\r\n`.
-pub fn write_system_newlines<T>(
-    writer: T,
-    text: &StringBuffer,
-    config: &Config,
-) -> Result<(), io::Error>
+pub fn write_system_newlines<T>(writer: T, text: &str, config: &Config) -> Result<(), io::Error>
 where
     T: Write,
 {
@@ -68,7 +65,7 @@ pub fn write_system_newlines<T>(
     match style {
         NewlineStyle::Unix => write!(writer, "{}", text),
         NewlineStyle::Windows => {
-            for (c, _) in text.chars() {
+            for c in text.chars() {
                 match c {
                     '\n' => write!(writer, "\r\n")?,
                     '\r' => continue,
@@ -82,7 +79,7 @@ pub fn write_system_newlines<T>(
 }
 
 pub fn write_file<T>(
-    text: &StringBuffer,
+    text: &str,
     filename: &str,
     out: &mut T,
     config: &Config,
@@ -91,7 +88,7 @@ pub fn write_file<T>(
     T: Write,
 {
     fn source_and_formatted_text(
-        text: &StringBuffer,
+        text: &str,
         filename: &str,
         config: &Config,
     ) -> Result<(String, String), io::Error> {
@@ -106,7 +103,7 @@ fn source_and_formatted_text(
 
     fn create_diff(
         filename: &str,
-        text: &StringBuffer,
+        text: &str,
         config: &Config,
     ) -> Result<Vec<Mismatch>, io::Error> {
         let (ori, fmt) = source_and_formatted_text(text, filename, config)?;
@@ -152,9 +149,11 @@ fn create_diff(
             if let Ok((ori, fmt)) = source_and_formatted_text(text, filename, config) {
                 let mismatch = make_diff(&ori, &fmt, 3);
                 let has_diff = !mismatch.is_empty();
-                print_diff(mismatch, |line_num| {
-                    format!("Diff in {} at line {}:", filename, line_num)
-                });
+                print_diff(
+                    mismatch,
+                    |line_num| format!("Diff in {} at line {}:", filename, line_num),
+                    config.color(),
+                );
                 return Ok(has_diff);
             }
         }