about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-12-01 14:08:10 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-12-04 15:42:06 +1100
commit114380d215931bef6037e2c9b16397a3071a1800 (patch)
treede6d7d38e1475ca559f7025c16113cde2c3ecd19
parent71940e0a8a87ec685b338384ff5b4d98c3d926c1 (diff)
downloadrust-114380d215931bef6037e2c9b16397a3071a1800.tar.gz
rust-114380d215931bef6037e2c9b16397a3071a1800.zip
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.
-rw-r--r--compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs2
-rw-r--r--compiler/rustc_errors/src/lib.rs13
-rw-r--r--compiler/rustc_session/src/session.rs2
3 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs b/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs
index 20f2ee4c76a..978891f2b0d 100644
--- a/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs
+++ b/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs
@@ -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.
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 5966fd80f97..383bec2fa8f 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -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
     }
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index c6f435a8f92..a53160a5ab4 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -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]