use std::{error, fmt, panic};
#[macro_export]
macro_rules! bug {
() => ( $crate::bug::bug("impossible case reached") );
($msg:expr) => ({ $crate::bug::bug(&format!($msg)) });
($msg:expr,) => ({ $crate::bug::bug($msg) });
($fmt:expr, $($arg:tt)+) => ({
$crate::bug::bug(&format!($fmt, $($arg)+))
});
}
#[derive(Clone, Debug)]
pub struct ExplicitBug {
msg: String,
}
impl fmt::Display for ExplicitBug {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Internal error, please report a bug to us. The error message is: {}",
self.msg
)
}
}
impl error::Error for ExplicitBug {}
#[inline]
pub fn bug(msg: &str) -> ! {
panic!(
"{}",
ExplicitBug {
msg: msg.to_string()
}
);
}