-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a bit unfortunate, but code needs to be able to fatally error early on (in particular, syntax_pos after we move SourceMap there). It's also a tiny bit of code, which means it's ultimately not that bad.
- Loading branch information
1 parent
82cf3a4
commit e1a87ca
Showing
3 changed files
with
32 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Used as a return value to signify a fatal error occurred. (It is also | ||
/// used as the argument to panic at the moment, but that will eventually | ||
/// not be true.) | ||
#[derive(Copy, Clone, Debug)] | ||
#[must_use] | ||
pub struct FatalError; | ||
|
||
pub struct FatalErrorMarker; | ||
|
||
// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError). | ||
// 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 { | ||
write!(f, "parser fatal error") | ||
} | ||
} | ||
|
||
impl std::error::Error for FatalError { | ||
fn description(&self) -> &str { | ||
"The parser has encountered a fatal error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters