]> git.lizzy.rs Git - rust.git/commitdiff
Write non-output to stderr when there is output
authorJason Dusek <jason.dusek@gmail.com>
Wed, 9 Mar 2016 05:52:58 +0000 (21:52 -0800)
committerJason Dusek <jason.dusek@gmail.com>
Fri, 11 Mar 2016 08:15:26 +0000 (00:15 -0800)
src/bin/rustfmt.rs

index 1524384fc1286594f6a6f1851400f0a58465c7be..b7492fdc2fe3c7515b24d28acc9cb1b1a12d9807 100644 (file)
 
 use getopts::{Matches, Options};
 
+macro_rules! msg(
+    ($($arg:tt)*) => (
+        match writeln!(&mut ::std::io::stderr(), $($arg)* ) {
+            Ok(_) => {},
+            Err(x) => panic!("Unable to write to stderr: {}", x),
+        }
+    )
+);
+
 /// Rustfmt operations.
 enum Operation {
     /// Format files and their child modules.
@@ -203,7 +212,7 @@ fn execute() -> i32 {
                 path = path_tmp;
             };
             if let Some(path) = path.as_ref() {
-                println!("Using rustfmt config file {}", path.display());
+                msg!("Using rustfmt config file {}", path.display());
             }
             for file in files {
                 // Check the file directory if the config-path could not be read or not provided
@@ -213,7 +222,7 @@ fn execute() -> i32 {
                                                                        for {}",
                                                                       file.display()));
                     if let Some(path) = path_tmp.as_ref() {
-                        println!("Using rustfmt config file {} for {}",
+                        msg!("Using rustfmt config file {} for {}",
                                  path.display(),
                                  file.display());
                     }