mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Merge pull request #909 from srinivasreddy/refactor
Refactoring so that we write some error messages to stderr rather than stdout.
This commit is contained in:
commit
c59d96a747
@ -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 {
|
||||
|
@ -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!();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/utils.rs
10
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: AsRef<str>>(s: S, max_width: usize, width: usize, offset: Indent) -> Option<S> {
|
||||
|
Loading…
Reference in New Issue
Block a user