From 8ef54478157adb980598104af0ce571cb6637931 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 25 Sep 2017 00:14:56 -0400 Subject: [PATCH] Migrate to eprint/eprintln macros where appropriate. --- src/bootstrap/bin/rustc.rs | 4 +--- src/librustc_driver/lib.rs | 2 +- src/librustdoc/externalfiles.rs | 9 ++------- src/librustdoc/markdown.rs | 14 +++----------- src/librustdoc/test.rs | 9 ++++----- src/libstd/process.rs | 4 +--- src/test/run-fail/mir_drop_panics.rs | 3 +-- src/test/run-fail/mir_dynamic_drops_1.rs | 5 ++--- src/test/run-fail/mir_dynamic_drops_2.rs | 5 ++--- src/test/run-fail/mir_dynamic_drops_3.rs | 5 ++--- .../run-fail/mir_trans_calls_converging_drops.rs | 6 ++---- .../run-fail/mir_trans_calls_converging_drops_2.rs | 6 ++---- .../run-fail/mir_trans_calls_diverging_drops.rs | 4 +--- src/test/run-fail/panic-set-handler.rs | 3 +-- src/test/run-fail/panic-set-unset-handler.rs | 3 +-- src/test/run-pass/backtrace-debuginfo.rs | 4 +--- src/tools/tidy/src/lib.rs | 5 ++--- src/tools/tidy/src/main.rs | 3 +-- 18 files changed, 30 insertions(+), 64 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 848b10d312c..54a3dbafe27 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -31,8 +31,6 @@ extern crate bootstrap; use std::env; use std::ffi::OsString; -use std::io; -use std::io::prelude::*; use std::str::FromStr; use std::path::PathBuf; use std::process::{Command, ExitStatus}; @@ -270,7 +268,7 @@ fn main() { } if verbose > 1 { - writeln!(&mut io::stderr(), "rustc command: {:?}", cmd).unwrap(); + eprintln!("rustc command: {:?}", cmd); } // Actually run the compiler! diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 044f4a5eaf5..29d15188500 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1307,7 +1307,7 @@ pub fn monitor(f: F) { errors::Level::Note); } - writeln!(io::stderr(), "{}", str::from_utf8(&data.lock().unwrap()).unwrap()).unwrap(); + eprintln!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); } exit_on_err(); diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 111ae4ede27..2f7bd5e39a1 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -10,7 +10,6 @@ use std::fs::File; use std::io::prelude::*; -use std::io; use std::path::Path; use std::str; use html::markdown::{Markdown, RenderType}; @@ -70,17 +69,13 @@ pub fn load_string>(file_path: P) -> Result Ok(s.to_string()), Err(_) => { - let _ = writeln!(&mut io::stderr(), - "error reading `{}`: not UTF-8", - file_path.display()); + eprintln!("error reading `{}`: not UTF-8", file_path.display()); Err(LoadStringError::BadUtf8) } } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 57e8e88cd13..484285e91f6 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -11,7 +11,6 @@ use std::default::Default; use std::fs::File; use std::io::prelude::*; -use std::io; use std::path::{PathBuf, Path}; use getopts; @@ -75,9 +74,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, let mut out = match File::create(&output) { Err(e) => { - let _ = writeln!(&mut io::stderr(), - "rustdoc: {}: {}", - output.display(), e); + eprintln!("rustdoc: {}: {}", output.display(), e); return 4; } Ok(f) => f @@ -85,10 +82,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, let (metadata, text) = extract_leading_metadata(&input_str); if metadata.is_empty() { - let _ = writeln!( - &mut io::stderr(), - "rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`" - ); + eprintln!("rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`"); return 5; } let title = metadata[0]; @@ -138,9 +132,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, match err { Err(e) => { - let _ = writeln!(&mut io::stderr(), - "rustdoc: cannot write to `{}`: {}", - output.display(), e); + eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e); 6 } Ok(_) => 0 diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index f9cb4b84545..5f6ccb8a75e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -479,11 +479,10 @@ impl Collector { found = entry.remove_item(&test).is_some(); } if !found { - let _ = writeln!(&mut io::stderr(), - "WARNING: {} Code block is not currently run as a test, but will \ - in future versions of rustdoc. Please ensure this code block is \ - a runnable test, or use the `ignore` directive.", - name); + eprintln!("WARNING: {} Code block is not currently run as a test, but will \ + in future versions of rustdoc. Please ensure this code block is \ + a runnable test, or use the `ignore` directive.", + name); return } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 1869ad3ed70..015f859b5cc 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1083,8 +1083,6 @@ impl Child { /// function and compute the exit code from its return value: /// /// ``` -/// use std::io::{self, Write}; -/// /// fn run_app() -> Result<(), ()> { /// // Application logic here /// Ok(()) @@ -1094,7 +1092,7 @@ impl Child { /// ::std::process::exit(match run_app() { /// Ok(_) => 0, /// Err(err) => { -/// writeln!(io::stderr(), "error: {:?}", err).unwrap(); +/// eprintln!("error: {:?}", err); /// 1 /// } /// }); diff --git a/src/test/run-fail/mir_drop_panics.rs b/src/test/run-fail/mir_drop_panics.rs index 98311525ad0..51191dd7087 100644 --- a/src/test/run-fail/mir_drop_panics.rs +++ b/src/test/run-fail/mir_drop_panics.rs @@ -10,7 +10,6 @@ // error-pattern:panic 1 // error-pattern:drop 2 -use std::io::{self, Write}; struct Droppable(u32); impl Drop for Droppable { @@ -18,7 +17,7 @@ impl Drop for Droppable { if self.0 == 1 { panic!("panic 1"); } else { - write!(io::stderr(), "drop {}", self.0); + eprint!("drop {}", self.0); } } } diff --git a/src/test/run-fail/mir_dynamic_drops_1.rs b/src/test/run-fail/mir_dynamic_drops_1.rs index 6cf2851d93d..69f934272b7 100644 --- a/src/test/run-fail/mir_dynamic_drops_1.rs +++ b/src/test/run-fail/mir_dynamic_drops_1.rs @@ -9,7 +9,6 @@ // except according to those terms. // error-pattern:drop 1 // error-pattern:drop 2 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -17,10 +16,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_dynamic_drops_2.rs b/src/test/run-fail/mir_dynamic_drops_2.rs index 7a90298e422..d2fe50401ab 100644 --- a/src/test/run-fail/mir_dynamic_drops_2.rs +++ b/src/test/run-fail/mir_dynamic_drops_2.rs @@ -9,7 +9,6 @@ // except according to those terms. // error-pattern:drop 1 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -17,10 +16,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_dynamic_drops_3.rs b/src/test/run-fail/mir_dynamic_drops_3.rs index 79ecbbb35bc..ecc35ee9b24 100644 --- a/src/test/run-fail/mir_dynamic_drops_3.rs +++ b/src/test/run-fail/mir_dynamic_drops_3.rs @@ -12,7 +12,6 @@ // error-pattern:drop 3 // error-pattern:drop 2 // error-pattern:drop 1 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -20,10 +19,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_trans_calls_converging_drops.rs b/src/test/run-fail/mir_trans_calls_converging_drops.rs index 7a7526c5fc1..9c851eb7346 100644 --- a/src/test/run-fail/mir_trans_calls_converging_drops.rs +++ b/src/test/run-fail/mir_trans_calls_converging_drops.rs @@ -12,17 +12,15 @@ // error-pattern:0 dropped // error-pattern:exit -use std::io::{self, Write}; - struct Droppable(u8); impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "{} dropped\n", self.0); + eprintln!("{} dropped", self.0); } } fn converging_fn() { - write!(io::stderr(), "converging_fn called\n"); + eprintln!("converging_fn called"); } fn mir(d: Droppable) { diff --git a/src/test/run-fail/mir_trans_calls_converging_drops_2.rs b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs index 1301630cc85..6f105211556 100644 --- a/src/test/run-fail/mir_trans_calls_converging_drops_2.rs +++ b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs @@ -12,18 +12,16 @@ // error-pattern:dropped // error-pattern:exit -use std::io::{self, Write}; - struct Droppable; impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "dropped\n"); + eprintln!("dropped"); } } // return value of this function is copied into the return slot fn complex() -> u64 { - write!(io::stderr(), "complex called\n"); + eprintln!("complex called"); 42 } diff --git a/src/test/run-fail/mir_trans_calls_diverging_drops.rs b/src/test/run-fail/mir_trans_calls_diverging_drops.rs index c1918704929..f8fbe8f79cc 100644 --- a/src/test/run-fail/mir_trans_calls_diverging_drops.rs +++ b/src/test/run-fail/mir_trans_calls_diverging_drops.rs @@ -11,12 +11,10 @@ // error-pattern:diverging_fn called // error-pattern:0 dropped -use std::io::{self, Write}; - struct Droppable(u8); impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "{} dropped", self.0); + eprintln!("{} dropped", self.0); } } diff --git a/src/test/run-fail/panic-set-handler.rs b/src/test/run-fail/panic-set-handler.rs index b589544ae15..68f1c4ed0bc 100644 --- a/src/test/run-fail/panic-set-handler.rs +++ b/src/test/run-fail/panic-set-handler.rs @@ -13,11 +13,10 @@ #![feature(panic_handler)] use std::panic; -use std::io::{self, Write}; fn main() { panic::set_hook(Box::new(|i| { - write!(io::stderr(), "greetings from the panic handler"); + eprint!("greetings from the panic handler"); })); panic!("foobar"); } diff --git a/src/test/run-fail/panic-set-unset-handler.rs b/src/test/run-fail/panic-set-unset-handler.rs index 6741c2d9c2c..072139a8c9b 100644 --- a/src/test/run-fail/panic-set-unset-handler.rs +++ b/src/test/run-fail/panic-set-unset-handler.rs @@ -13,11 +13,10 @@ #![feature(panic_handler)] use std::panic; -use std::io::{self, Write}; fn main() { panic::set_hook(Box::new(|i| { - write!(io::stderr(), "greetings from the panic handler"); + eprint!("greetings from the panic handler"); })); panic::take_hook(); panic!("foobar"); diff --git a/src/test/run-pass/backtrace-debuginfo.rs b/src/test/run-pass/backtrace-debuginfo.rs index f81352e1773..f9233026a1e 100644 --- a/src/test/run-pass/backtrace-debuginfo.rs +++ b/src/test/run-pass/backtrace-debuginfo.rs @@ -19,8 +19,6 @@ // ignore-pretty issue #37195 // ignore-emscripten spawning processes is not supported -use std::io; -use std::io::prelude::*; use std::env; #[path = "backtrace-debuginfo-aux.rs"] mod aux; @@ -163,7 +161,7 @@ fn main() { let args: Vec = env::args().collect(); if args.len() >= 2 { let case = args[1].parse().unwrap(); - writeln!(&mut io::stderr(), "test case {}", case).unwrap(); + eprintln!("test case {}", case); outer(case, pos!()); println!("done."); } else { diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 90bf7a5e0a6..c316ec46762 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -33,10 +33,9 @@ macro_rules! t { macro_rules! tidy_error { ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ - use std::io::Write; *$bad = true; - write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr"); - writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr"); + eprint!("tidy error: "); + eprintln!($fmt, $($arg)*); }); } diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 433192a21ec..f6640c902bc 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -22,7 +22,6 @@ use tidy::*; use std::process; use std::path::PathBuf; use std::env; -use std::io::{self, Write}; fn main() { let path = env::args_os().skip(1).next().expect("need an argument"); @@ -44,7 +43,7 @@ fn main() { } if bad { - writeln!(io::stderr(), "some tidy checks failed").expect("could not write to stderr"); + eprintln!("some tidy checks failed"); process::exit(1); } }