]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_span/src/fatal_error.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / compiler / rustc_span / src / fatal_error.rs
CommitLineData
60c5eb7d
XL
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]
6pub struct FatalError;
7
8pub 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.
12impl !Send for FatalError {}
13
14impl FatalError {
15 pub fn raise(self) -> ! {
16 std::panic::resume_unwind(Box::new(FatalErrorMarker))
17 }
18}
19
20impl std::fmt::Display for FatalError {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5e7ed085 22 write!(f, "fatal error")
60c5eb7d
XL
23 }
24}
25
dfeec247 26impl std::error::Error for FatalError {}