1 /// Used as a return value to signify a fatal error occurred. (It is also 2 /// used as the argument to panic at the moment, but that will eventually 3 /// not be true.) 4 #[derive(Copy, Clone, Debug)] 5 #[must_use] 6 pub struct FatalError; 7 8 pub struct FatalErrorMarker; 9 10 // Don't implement Send on FatalError. This makes it impossible to panic!(FatalError). 11 // We don't want to invoke the panic handler and print a backtrace for fatal errors. 12 impl !Send for FatalError {} 13 14 impl FatalError { raise(self) -> !15 pub fn raise(self) -> ! { 16 std::panic::resume_unwind(Box::new(FatalErrorMarker)) 17 } 18 } 19 20 impl std::fmt::Display for FatalError { fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 22 write!(f, "fatal error") 23 } 24 } 25 26 impl std::error::Error for FatalError {} 27