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.
This commit is contained in:
Nicholas Nethercote 2023-12-01 14:08:10 +11:00
parent 71940e0a8a
commit 114380d215
3 changed files with 9 additions and 8 deletions

View file

@ -64,7 +64,7 @@ impl ConcurrencyLimiter {
// Make sure to drop the mutex guard first to prevent poisoning the mutex.
drop(state);
if let Some(err) = err {
handler.fatal(err).raise();
handler.fatal(err);
} else {
// The error was already emitted, but compilation continued. Raise a silent
// fatal error.

View file

@ -1034,10 +1034,9 @@ impl Handler {
db
}
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
#[rustc_lint_diagnostics]
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
self.inner.borrow_mut().fatal(msg)
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
self.inner.borrow_mut().fatal_no_raise(msg).raise()
}
#[rustc_lint_diagnostics]
@ -1469,10 +1468,10 @@ impl HandlerInner {
DiagnosticMessage::Str(warnings),
)),
(_, 0) => {
let _ = self.fatal(errors);
let _ = self.fatal_no_raise(errors);
}
(_, _) => {
let _ = self.fatal(format!("{errors}; {warnings}"));
let _ = self.fatal_no_raise(format!("{errors}; {warnings}"));
}
}
@ -1631,7 +1630,9 @@ impl HandlerInner {
self.emit_diagnostic(&mut Diagnostic::new(FailureNote, msg));
}
fn fatal(&mut self, msg: impl Into<DiagnosticMessage>) -> FatalError {
// Note: unlike `Handler::fatal`, this doesn't return `!`, because that is
// inappropriate for some of its call sites.
fn fatal_no_raise(&mut self, msg: impl Into<DiagnosticMessage>) -> FatalError {
self.emit(Fatal, msg);
FatalError
}

View file

@ -461,7 +461,7 @@ impl Session {
}
#[rustc_lint_diagnostics]
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
self.diagnostic().fatal(msg).raise()
self.diagnostic().fatal(msg)
}
#[rustc_lint_diagnostics]
#[track_caller]