2023-10-31 02:25:46 +00:00
|
|
|
/// Used as a return value to signify a fatal error occurred.
|
2019-11-14 19:01:03 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
#[must_use]
|
|
|
|
pub struct FatalError;
|
|
|
|
|
2023-11-03 09:56:30 +00:00
|
|
|
pub use rustc_data_structures::FatalErrorMarker;
|
2019-11-14 19:01:03 +00:00
|
|
|
|
2023-10-31 02:25:46 +00:00
|
|
|
// Don't implement Send on FatalError. This makes it impossible to `panic_any!(FatalError)`.
|
2019-11-14 19:01:03 +00:00
|
|
|
// We don't want to invoke the panic handler and print a backtrace for fatal errors.
|
|
|
|
impl !Send for FatalError {}
|
|
|
|
|
|
|
|
impl FatalError {
|
|
|
|
pub fn raise(self) -> ! {
|
|
|
|
std::panic::resume_unwind(Box::new(FatalErrorMarker))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for FatalError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
2022-03-10 00:11:28 +00:00
|
|
|
write!(f, "fatal error")
|
2019-11-14 19:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-01 04:01:48 +00:00
|
|
|
impl std::error::Error for FatalError {}
|