From 901c5b1a5d45be3b9fe449716f779e31520e5882 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Wed, 6 Apr 2016 10:04:29 +0530 Subject: [PATCH] use std::error instead std::out --- src/bin/rustfmt.rs | 10 +--------- src/config.rs | 5 +++-- src/lib.rs | 4 ++-- src/utils.rs | 10 ++++++++++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index bce8ac7bc0f..b65cbaa7f59 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -10,7 +10,7 @@ #![cfg(not(test))] -#[macro_use] + extern crate log; extern crate rustfmt; extern crate toml; @@ -28,14 +28,6 @@ use std::str::FromStr; 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 { diff --git a/src/config.rs b/src/config.rs index 0b4b16c328e..46c28322c92 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,7 @@ extern crate toml; use lists::{SeparatorTactic, ListTactic}; +use std::io::Write; macro_rules! configuration_option_enum{ ($e:ident: $( $x:ident ),+ $(,)*) => { @@ -222,9 +223,9 @@ macro_rules! create_config { let parsed_config:ParsedConfig = match toml::decode(parsed) { Some(decoded) => decoded, None => { - println!("Decoding config file failed. Config:\n{}", toml); + msg!("Decoding config file failed. Config:\n{}", toml); let parsed: toml::Value = toml.parse().expect("Could not parse TOML"); - println!("\n\nParsed:\n{:?}", parsed); + msg!("\n\nParsed:\n{:?}", parsed); panic!(); } }; diff --git a/src/lib.rs b/src/lib.rs index 8c69710e359..b7af96ac5aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ use syntax::errors::Handler; use syntax::errors::emitter::{ColorConfig, EmitterWriter}; use syntax::parse::{self, ParseSess}; -use std::io::stdout; +use std::io::{stdout, Write}; use std::ops::{Add, Sub}; use std::path::{Path, PathBuf}; use std::rc::Rc; @@ -456,7 +456,7 @@ pub fn run(input: Input, config: &Config) { if let Err(msg) = write_result { if !ignore_errors { - println!("Error writing files: {}", msg); + msg!("Error writing files: {}", msg); } } } diff --git a/src/utils.rs b/src/utils.rs index 902969b9618..66b9880777f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -232,6 +232,16 @@ macro_rules! try_opt { }) } +macro_rules! msg { + ($($arg:tt)*) => ( + match writeln!(&mut ::std::io::stderr(), $($arg)* ) { + Ok(_) => {}, + Err(x) => panic!("Unable to write to stderr: {}", x), + } + ) +} + + // Wraps string-like values in an Option. Returns Some when the string adheres // to the Rewrite constraints defined for the Rewrite trait and else otherwise. pub fn wrap_str>(s: S, max_width: usize, width: usize, offset: Indent) -> Option {