rustc_span/fatal_error.rs
1/// Used as a return value to signify a fatal error occurred.
2#[derive(Copy, Clone, Debug)]
3#[must_use]
4pub struct FatalError;
5
6pub use rustc_data_structures::FatalErrorMarker;
7
8// Don't implement Send on FatalError. This makes it impossible to `panic_any!(FatalError)`.
9// We don't want to invoke the panic handler and print a backtrace for fatal errors.
10impl !Send for FatalError {}
11
12impl FatalError {
13 pub fn raise(self) -> ! {
14 std::panic::resume_unwind(Box::new(FatalErrorMarker))
15 }
16}
17
18impl std::fmt::Display for FatalError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "fatal error")
21 }
22}
23
24impl std::error::Error for FatalError {}