@@ -495,32 +495,31 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
495495 // - Panic, e.g. triggered by `abort_if_errors` or a fatal error.
496496 //
497497 // We must run `finish_diagnostics` in both cases.
498- let res = {
499- let res = std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || f ( & compiler) ) ) ;
500-
501- compiler. sess . finish_diagnostics ( ) ;
502-
503- // If error diagnostics have been emitted, we can't return an
504- // error directly, because the return type of this function
505- // is `R`, not `Result<R, E>`. But we need to communicate the
506- // errors' existence to the caller, otherwise the caller might
507- // mistakenly think that no errors occurred and return a zero
508- // exit code. So we abort (panic) instead, similar to if `f`
509- // had panicked.
510- if res. is_ok ( ) {
511- compiler. sess . dcx ( ) . abort_if_errors ( ) ;
512- }
498+ let res = std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || f ( & compiler) ) ) ;
499+
500+ compiler. sess . finish_diagnostics ( ) ;
501+
502+ // If error diagnostics have been emitted, we can't return an
503+ // error directly, because the return type of this function
504+ // is `R`, not `Result<R, E>`. But we need to communicate the
505+ // errors' existence to the caller, otherwise the caller might
506+ // mistakenly think that no errors occurred and return a zero
507+ // exit code. So we abort (panic) instead, similar to if `f`
508+ // had panicked.
509+ if res. is_ok ( ) {
510+ compiler. sess . dcx ( ) . abort_if_errors ( ) ;
511+ }
513512
514- // Also make sure to flush delayed bugs as if we panicked, the
515- // bugs would be flushed by the Drop impl of DiagCtxt while
516- // unwinding, which would result in an abort with
517- // "panic in a destructor during cleanup".
518- compiler. sess . dcx ( ) . flush_delayed ( ) ;
513+ // Also make sure to flush delayed bugs as if we panicked, the
514+ // bugs would be flushed by the Drop impl of DiagCtxt while
515+ // unwinding, which would result in an abort with
516+ // "panic in a destructor during cleanup".
517+ compiler. sess . dcx ( ) . flush_delayed ( ) ;
519518
520- match res {
521- Ok ( res) => res,
522- Err ( err ) => std :: panic:: resume_unwind ( err ) ,
523- }
519+ let res = match res {
520+ Ok ( res) => res,
521+ // Resume unwinding if a panic happened.
522+ Err ( err ) => std :: panic :: resume_unwind ( err ) ,
524523 } ;
525524
526525 let prof = compiler. sess . prof . clone ( ) ;
0 commit comments