Move FatalError to syntax_pos
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.
This commit is contained in:
parent
82cf3a4486
commit
e1a87ca17a
3 changed files with 32 additions and 30 deletions
|
@ -259,36 +259,7 @@ impl CodeSuggestion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used as a return value to signify a fatal error occurred. (It is also
|
pub use syntax_pos::fatal_error::{FatalError, FatalErrorMarker};
|
||||||
/// 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) -> ! {
|
|
||||||
panic::resume_unwind(Box::new(FatalErrorMarker))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for FatalError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "parser fatal error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl error::Error for FatalError {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
"The parser has encountered a fatal error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signifies that the compiler died with an explicit call to `.bug`
|
/// Signifies that the compiler died with an explicit call to `.bug`
|
||||||
/// or `.span_bug` rather than a failed assertion, etc.
|
/// or `.span_bug` rather than a failed assertion, etc.
|
||||||
|
|
30
src/libsyntax_pos/fatal_error.rs
Normal file
30
src/libsyntax_pos/fatal_error.rs
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ pub mod symbol;
|
||||||
pub use symbol::{Symbol, sym};
|
pub use symbol::{Symbol, sym};
|
||||||
|
|
||||||
mod analyze_source_file;
|
mod analyze_source_file;
|
||||||
|
pub mod fatal_error;
|
||||||
|
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use rustc_data_structures::sync::{Lrc, Lock};
|
use rustc_data_structures::sync::{Lrc, Lock};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue