Fix ICE on --print=... i/o errors

This commit is contained in:
David Tolnay 2023-04-24 17:04:26 -07:00
parent 521de433f4
commit 040e1b6b5f
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 68 additions and 40 deletions

View file

@ -0,0 +1,20 @@
use std::fmt;
use std::io::{self, Write as _};
macro_rules! safe_print {
($($arg:tt)*) => {{
$crate::print::print(std::format_args!($($arg)*));
}};
}
macro_rules! safe_println {
($($arg:tt)*) => {
safe_print!("{}\n", std::format_args!($($arg)*))
};
}
pub(crate) fn print(args: fmt::Arguments<'_>) {
if let Err(_) = io::stdout().write_fmt(args) {
rustc_errors::FatalError.raise();
}
}