1
Fork 0

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. // Make sure to drop the mutex guard first to prevent poisoning the mutex.
drop(state); drop(state);
if let Some(err) = err { if let Some(err) = err {
handler.fatal(err).raise(); handler.fatal(err);
} else { } else {
// The error was already emitted, but compilation continued. Raise a silent // The error was already emitted, but compilation continued. Raise a silent
// fatal error. // fatal error.

View file

@ -1034,10 +1034,9 @@ impl Handler {
db db
} }
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError { pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
self.inner.borrow_mut().fatal(msg) self.inner.borrow_mut().fatal_no_raise(msg).raise()
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
@ -1469,10 +1468,10 @@ impl HandlerInner {
DiagnosticMessage::Str(warnings), DiagnosticMessage::Str(warnings),
)), )),
(_, 0) => { (_, 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)); 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); self.emit(Fatal, msg);
FatalError FatalError
} }

View file

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