@@ -1138,6 +1138,16 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
1138
1138
} )
1139
1139
}
1140
1140
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
+
1141
1151
lazy_static ! {
1142
1152
static ref DEFAULT_HOOK : Box <dyn Fn ( & panic:: PanicInfo <' _>) + Sync + Send + ' static > = {
1143
1153
let hook = panic:: take_hook( ) ;
@@ -1233,7 +1243,7 @@ pub fn main() {
1233
1243
init_rustc_env_logger ( ) ;
1234
1244
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1235
1245
install_ice_hook ( ) ;
1236
- let result = catch_fatal_errors ( || {
1246
+ let exit_code = catch_with_exit_code ( || {
1237
1247
let args = env:: args_os ( )
1238
1248
. enumerate ( )
1239
1249
. map ( |( i, arg) | {
@@ -1246,12 +1256,7 @@ pub fn main() {
1246
1256
} )
1247
1257
. collect :: < Vec < _ > > ( ) ;
1248
1258
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
+ } ) ;
1255
1260
// The extra `\t` is necessary to align this label with the others.
1256
1261
print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
1257
1262
process:: exit ( exit_code) ;
0 commit comments