@@ -1138,6 +1138,16 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
11381138 } )
11391139}
11401140
1141+ /// Variant of `catch_fatal_errors` for the `interface::Result` return type
1142+ /// that also computes the exit code.
1143+ pub fn catch_with_exit_code ( f : impl FnOnce ( ) -> interface:: Result < ( ) > ) -> i32 {
1144+ let result = catch_fatal_errors ( f) . and_then ( |result| result) ;
1145+ match result {
1146+ Ok ( ( ) ) => EXIT_SUCCESS ,
1147+ Err ( _) => EXIT_FAILURE ,
1148+ }
1149+ }
1150+
11411151lazy_static ! {
11421152 static ref DEFAULT_HOOK : Box <dyn Fn ( & panic:: PanicInfo <' _>) + Sync + Send + ' static > = {
11431153 let hook = panic:: take_hook( ) ;
@@ -1233,7 +1243,7 @@ pub fn main() {
12331243 init_rustc_env_logger ( ) ;
12341244 let mut callbacks = TimePassesCallbacks :: default ( ) ;
12351245 install_ice_hook ( ) ;
1236- let result = catch_fatal_errors ( || {
1246+ let exit_code = catch_with_exit_code ( || {
12371247 let args = env:: args_os ( )
12381248 . enumerate ( )
12391249 . map ( |( i, arg) | {
@@ -1246,12 +1256,7 @@ pub fn main() {
12461256 } )
12471257 . collect :: < Vec < _ > > ( ) ;
12481258 run_compiler ( & args, & mut callbacks, None , None )
1249- } )
1250- . and_then ( |result| result) ;
1251- let exit_code = match result {
1252- Ok ( _) => EXIT_SUCCESS ,
1253- Err ( _) => EXIT_FAILURE ,
1254- } ;
1259+ } ) ;
12551260 // The extra `\t` is necessary to align this label with the others.
12561261 print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
12571262 process:: exit ( exit_code) ;
0 commit comments