Skip to content

Commit e1a87ca

Browse files
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.
1 parent 82cf3a4 commit e1a87ca

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

src/librustc_errors/lib.rs

+1-30
Original file line numberDiff line numberDiff line change
@@ -259,36 +259,7 @@ impl CodeSuggestion {
259259
}
260260
}
261261

262-
/// Used as a return value to signify a fatal error occurred. (It is also
263-
/// used as the argument to panic at the moment, but that will eventually
264-
/// not be true.)
265-
#[derive(Copy, Clone, Debug)]
266-
#[must_use]
267-
pub struct FatalError;
268-
269-
pub struct FatalErrorMarker;
270-
271-
// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError).
272-
// We don't want to invoke the panic handler and print a backtrace for fatal errors.
273-
impl !Send for FatalError {}
274-
275-
impl FatalError {
276-
pub fn raise(self) -> ! {
277-
panic::resume_unwind(Box::new(FatalErrorMarker))
278-
}
279-
}
280-
281-
impl fmt::Display for FatalError {
282-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
283-
write!(f, "parser fatal error")
284-
}
285-
}
286-
287-
impl error::Error for FatalError {
288-
fn description(&self) -> &str {
289-
"The parser has encountered a fatal error"
290-
}
291-
}
262+
pub use syntax_pos::fatal_error::{FatalError, FatalErrorMarker};
292263

293264
/// Signifies that the compiler died with an explicit call to `.bug`
294265
/// or `.span_bug` rather than a failed assertion, etc.

src/libsyntax_pos/fatal_error.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 {
15+
pub fn raise(self) -> ! {
16+
std::panic::resume_unwind(Box::new(FatalErrorMarker))
17+
}
18+
}
19+
20+
impl std::fmt::Display for FatalError {
21+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22+
write!(f, "parser fatal error")
23+
}
24+
}
25+
26+
impl std::error::Error for FatalError {
27+
fn description(&self) -> &str {
28+
"The parser has encountered a fatal error"
29+
}
30+
}

src/libsyntax_pos/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod symbol;
2929
pub use symbol::{Symbol, sym};
3030

3131
mod analyze_source_file;
32+
pub mod fatal_error;
3233

3334
use rustc_data_structures::stable_hasher::StableHasher;
3435
use rustc_data_structures::sync::{Lrc, Lock};

0 commit comments

Comments
 (0)