Skip to content

Commit c59d96a

Browse files
committed
Merge pull request #909 from srinivasreddy/refactor
Refactoring so that we write some error messages to stderr rather than stdout.
2 parents ea76677 + 901c5b1 commit c59d96a

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/bin/rustfmt.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![cfg(not(test))]
1212

13-
#[macro_use]
13+
1414
extern crate log;
1515
extern crate rustfmt;
1616
extern crate toml;
@@ -28,14 +28,6 @@ use std::str::FromStr;
2828

2929
use getopts::{Matches, Options};
3030

31-
macro_rules! msg {
32-
($($arg:tt)*) => (
33-
match writeln!(&mut ::std::io::stderr(), $($arg)* ) {
34-
Ok(_) => {},
35-
Err(x) => panic!("Unable to write to stderr: {}", x),
36-
}
37-
)
38-
}
3931

4032
/// Rustfmt operations.
4133
enum Operation {

src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
extern crate toml;
1212

1313
use lists::{SeparatorTactic, ListTactic};
14+
use std::io::Write;
1415

1516
macro_rules! configuration_option_enum{
1617
($e:ident: $( $x:ident ),+ $(,)*) => {
@@ -222,9 +223,9 @@ macro_rules! create_config {
222223
let parsed_config:ParsedConfig = match toml::decode(parsed) {
223224
Some(decoded) => decoded,
224225
None => {
225-
println!("Decoding config file failed. Config:\n{}", toml);
226+
msg!("Decoding config file failed. Config:\n{}", toml);
226227
let parsed: toml::Value = toml.parse().expect("Could not parse TOML");
227-
println!("\n\nParsed:\n{:?}", parsed);
228+
msg!("\n\nParsed:\n{:?}", parsed);
228229
panic!();
229230
}
230231
};

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::errors::Handler;
3131
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
3232
use syntax::parse::{self, ParseSess};
3333

34-
use std::io::stdout;
34+
use std::io::{stdout, Write};
3535
use std::ops::{Add, Sub};
3636
use std::path::{Path, PathBuf};
3737
use std::rc::Rc;
@@ -456,7 +456,7 @@ pub fn run(input: Input, config: &Config) {
456456

457457
if let Err(msg) = write_result {
458458
if !ignore_errors {
459-
println!("Error writing files: {}", msg);
459+
msg!("Error writing files: {}", msg);
460460
}
461461
}
462462
}

src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ macro_rules! try_opt {
232232
})
233233
}
234234

235+
macro_rules! msg {
236+
($($arg:tt)*) => (
237+
match writeln!(&mut ::std::io::stderr(), $($arg)* ) {
238+
Ok(_) => {},
239+
Err(x) => panic!("Unable to write to stderr: {}", x),
240+
}
241+
)
242+
}
243+
244+
235245
// Wraps string-like values in an Option. Returns Some when the string adheres
236246
// to the Rewrite constraints defined for the Rewrite trait and else otherwise.
237247
pub fn wrap_str<S: AsRef<str>>(s: S, max_width: usize, width: usize, offset: Indent) -> Option<S> {

0 commit comments

Comments
 (0)