about summary refs log tree commit diff
path: root/compiler/rustc_interface/src/interface.rs
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-12-07 17:13:33 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-12-07 17:13:33 +0000
commit23fda35811f15c368843ac7ee20a03a18a2b2fa0 (patch)
tree3fd0d4e1f98299ae7c5e61e53ec3d32a7804e26d /compiler/rustc_interface/src/interface.rs
parent85414ebea7f48a963aa6effebd18b91d1fe512ba (diff)
downloadrust-23fda35811f15c368843ac7ee20a03a18a2b2fa0.tar.gz
rust-23fda35811f15c368843ac7ee20a03a18a2b2fa0.zip
Reduce indentation in run_compiler
Diffstat (limited to 'compiler/rustc_interface/src/interface.rs')
-rw-r--r--compiler/rustc_interface/src/interface.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index a631e9cd93c..07ae24ee6d3 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -495,32 +495,31 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
             // - Panic, e.g. triggered by `abort_if_errors` or a fatal error.
             //
             // We must run `finish_diagnostics` in both cases.
-            let res = {
-                let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(&compiler)));
-
-                compiler.sess.finish_diagnostics();
-
-                // If error diagnostics have been emitted, we can't return an
-                // error directly, because the return type of this function
-                // is `R`, not `Result<R, E>`. But we need to communicate the
-                // errors' existence to the caller, otherwise the caller might
-                // mistakenly think that no errors occurred and return a zero
-                // exit code. So we abort (panic) instead, similar to if `f`
-                // had panicked.
-                if res.is_ok() {
-                    compiler.sess.dcx().abort_if_errors();
-                }
+            let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(&compiler)));
+
+            compiler.sess.finish_diagnostics();
+
+            // If error diagnostics have been emitted, we can't return an
+            // error directly, because the return type of this function
+            // is `R`, not `Result<R, E>`. But we need to communicate the
+            // errors' existence to the caller, otherwise the caller might
+            // mistakenly think that no errors occurred and return a zero
+            // exit code. So we abort (panic) instead, similar to if `f`
+            // had panicked.
+            if res.is_ok() {
+                compiler.sess.dcx().abort_if_errors();
+            }
 
-                // Also make sure to flush delayed bugs as if we panicked, the
-                // bugs would be flushed by the Drop impl of DiagCtxt while
-                // unwinding, which would result in an abort with
-                // "panic in a destructor during cleanup".
-                compiler.sess.dcx().flush_delayed();
+            // Also make sure to flush delayed bugs as if we panicked, the
+            // bugs would be flushed by the Drop impl of DiagCtxt while
+            // unwinding, which would result in an abort with
+            // "panic in a destructor during cleanup".
+            compiler.sess.dcx().flush_delayed();
 
-                match res {
-                    Ok(res) => res,
-                    Err(err) => std::panic::resume_unwind(err),
-                }
+            let res = match res {
+                Ok(res) => res,
+                // Resume unwinding if a panic happened.
+                Err(err) => std::panic::resume_unwind(err),
             };
 
             let prof = compiler.sess.prof.clone();