use std::fmt::Arguments;
use std::io;
use std::process;
macro_rules! rtabort {
($m:literal) => {
$crate::util::rtabort::rtabort_impl_fixed_string(
file!(),
line!(),
$m,
)
};
($($t:tt)*) => {
$crate::util::rtabort::rtabort_impl(
file!(),
line!(),
format_args!($($t)*),
)
};
}
pub(crate) use rtabort;
#[cold]
pub(crate) fn rtabort_impl_fixed_string(file: &str, line: u32, message: &str) -> ! {
rtabort_impl(file, line, format_args!("{}", message));
}
#[cold]
pub(crate) fn rtabort_impl(file: &str, line: u32, msg: Arguments) -> ! {
let _abort = AbortOnDrop;
io::Write::write_fmt(
&mut io::stderr(),
format_args!("{}:{}: abort: {}\n", file, line, msg),
)
.ok();
process::abort();
}
struct AbortOnDrop;
impl Drop for AbortOnDrop {
fn drop(&mut self) {
process::abort();
}
}
#[cfg(test)]
mod tests {
fn _test_compiles_fixed_string() {
rtabort!("test");
}
fn _test_compiles_with_format_args() {
rtabort!("test {}", 17);
}
#[test]
fn test_rtabort() {
}
}