]> git.lizzy.rs Git - rust.git/blobdiff - src/checkstyle.rs
Merge pull request #2138 from topecongiro/comments-around-trait-bounds
[rust.git] / src / checkstyle.rs
index 02e214864fad31cb52efe1a4edf28ecfa2da8027..0934ed3f71920f91542a0507ecd9bad0d484d61d 100644 (file)
@@ -7,60 +7,63 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-use rustfmt_diff::{Mismatch, DiffLine};
-use std::io::{self, Write, Read};
-use config::WriteMode;
 
+use std::io::{self, Write};
+
+use config::WriteMode;
+use rustfmt_diff::{DiffLine, Mismatch};
 
 pub fn output_header<T>(out: &mut T, mode: WriteMode) -> Result<(), io::Error>
-    where T: Write
+where
+    T: Write,
 {
     if mode == WriteMode::Checkstyle {
         let mut xml_heading = String::new();
         xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
         xml_heading.push_str("\n");
         xml_heading.push_str("<checkstyle version=\"4.3\">");
-        try!(write!(out, "{}", xml_heading));
+        write!(out, "{}", xml_heading)?;
     }
     Ok(())
 }
 
 pub fn output_footer<T>(out: &mut T, mode: WriteMode) -> Result<(), io::Error>
-    where T: Write
+where
+    T: Write,
 {
     if mode == WriteMode::Checkstyle {
         let mut xml_tail = String::new();
         xml_tail.push_str("</checkstyle>");
-        try!(write!(out, "{}", xml_tail));
+        write!(out, "{}", xml_tail)?;
     }
     Ok(())
 }
 
-pub fn output_checkstyle_file<T>(mut writer: T,
-                                 filename: &str,
-                                 diff: Vec<Mismatch>)
-                                 -> Result<(), io::Error>
-    where T: Write
+pub fn output_checkstyle_file<T>(
+    mut writer: T,
+    filename: &str,
+    diff: Vec<Mismatch>,
+) -> Result<(), io::Error>
+where
+    T: Write,
 {
-    try!(write!(writer, "<file name=\"{}\">", filename));
+    write!(writer, "<file name=\"{}\">", filename)?;
     for mismatch in diff {
         for line in mismatch.lines {
-            match line {
-                DiffLine::Expected(ref str) => {
-                    let message = xml_escape_str(&str);
-                    try!(write!(writer,
-                                "<error line=\"{}\" severity=\"warning\" message=\"Should be \
-                                 `{}`\" />",
-                                mismatch.line_number,
-                                message));
-                }
-                _ => {
-                    // Do nothing with context and expected.
-                }
+            // Do nothing with `DiffLine::Context` and `DiffLine::Resulting`.
+            if let DiffLine::Expected(ref str) = line {
+                let message = xml_escape_str(str);
+                write!(
+                    writer,
+                    "<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
+                     />",
+                    mismatch.line_number,
+                    message
+                )?;
             }
         }
     }
-    try!(write!(writer, "</file>"));
+    write!(writer, "</file>")?;
     Ok(())
 }