1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();
    }
}