Skip to content

Migrate to eprint/eprintln macros where appropriate. #44822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(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();
Expand Down
9 changes: 2 additions & 7 deletions src/librustdoc/externalfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -70,17 +69,13 @@ pub fn load_string<P: AsRef<Path>>(file_path: P) -> Result<String, LoadStringErr
let result = File::open(file_path)
.and_then(|mut f| f.read_to_end(&mut contents));
if let Err(e) = result {
let _ = writeln!(&mut io::stderr(),
"error reading `{}`: {}",
file_path.display(), e);
eprintln!("error reading `{}`: {}", file_path.display(), e);
return Err(LoadStringError::ReadFail);
}
match str::from_utf8(&contents) {
Ok(s) => 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)
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,20 +74,15 @@ 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
};

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];
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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
/// }
/// });
Expand Down
3 changes: 1 addition & 2 deletions src/test/run-fail/mir_drop_panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

// error-pattern:panic 1
// error-pattern:drop 2
use std::io::{self, Write};

struct Droppable(u32);
impl Drop for Droppable {
fn drop(&mut self) {
if self.0 == 1 {
panic!("panic 1");
} else {
write!(io::stderr(), "drop {}", self.0);
eprint!("drop {}", self.0);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-fail/mir_dynamic_drops_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
// 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.
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;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-fail/mir_dynamic_drops_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
// except according to those terms.

// error-pattern:drop 1
use std::io::{self, Write};


/// Structure which will not allow to be dropped twice.
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;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-fail/mir_dynamic_drops_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
// 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.
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;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/test/run-fail/mir_trans_calls_converging_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions src/test/run-fail/mir_trans_calls_converging_drops_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/run-fail/mir_trans_calls_diverging_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/run-fail/panic-set-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
3 changes: 1 addition & 2 deletions src/test/run-fail/panic-set-unset-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions src/test/run-pass/backtrace-debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -163,7 +161,7 @@ fn main() {
let args: Vec<String> = 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 {
Expand Down
5 changes: 2 additions & 3 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
}