Skip to content

Commit 114380d

Browse files
committed
Give Handler::fatal and Session::fatal the same return type.
Currently, `Handler::fatal` returns `FatalError`. But `Session::fatal` returns `!`, because it calls `Handler::fatal` and then calls `raise` on the result. This inconsistency is unfortunate. This commit changes `Handler::fatal` to do the `raise` itself, changing its return type to `!`. This is safe because there are only two calls to `Handler::fatal`, one in `rustc_session` and one in `rustc_codegen_cranelift`, and they both call `raise` on the result. `HandlerInner::fatal` still returns `FatalError`, so I renamed it `fatal_no_raise` to emphasise the return type difference.
1 parent 71940e0 commit 114380d

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl ConcurrencyLimiter {
6464
// Make sure to drop the mutex guard first to prevent poisoning the mutex.
6565
drop(state);
6666
if let Some(err) = err {
67-
handler.fatal(err).raise();
67+
handler.fatal(err);
6868
} else {
6969
// The error was already emitted, but compilation continued. Raise a silent
7070
// fatal error.

compiler/rustc_errors/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,9 @@ impl Handler {
10341034
db
10351035
}
10361036

1037-
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
10381037
#[rustc_lint_diagnostics]
1039-
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
1040-
self.inner.borrow_mut().fatal(msg)
1038+
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
1039+
self.inner.borrow_mut().fatal_no_raise(msg).raise()
10411040
}
10421041

10431042
#[rustc_lint_diagnostics]
@@ -1469,10 +1468,10 @@ impl HandlerInner {
14691468
DiagnosticMessage::Str(warnings),
14701469
)),
14711470
(_, 0) => {
1472-
let _ = self.fatal(errors);
1471+
let _ = self.fatal_no_raise(errors);
14731472
}
14741473
(_, _) => {
1475-
let _ = self.fatal(format!("{errors}; {warnings}"));
1474+
let _ = self.fatal_no_raise(format!("{errors}; {warnings}"));
14761475
}
14771476
}
14781477

@@ -1631,7 +1630,9 @@ impl HandlerInner {
16311630
self.emit_diagnostic(&mut Diagnostic::new(FailureNote, msg));
16321631
}
16331632

1634-
fn fatal(&mut self, msg: impl Into<DiagnosticMessage>) -> FatalError {
1633+
// Note: unlike `Handler::fatal`, this doesn't return `!`, because that is
1634+
// inappropriate for some of its call sites.
1635+
fn fatal_no_raise(&mut self, msg: impl Into<DiagnosticMessage>) -> FatalError {
16351636
self.emit(Fatal, msg);
16361637
FatalError
16371638
}

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl Session {
461461
}
462462
#[rustc_lint_diagnostics]
463463
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
464-
self.diagnostic().fatal(msg).raise()
464+
self.diagnostic().fatal(msg)
465465
}
466466
#[rustc_lint_diagnostics]
467467
#[track_caller]

0 commit comments

Comments
 (0)