diff options
| author | Ralf Jung <post@ralfj.de> | 2020-05-10 23:36:41 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-05-10 23:36:41 +0200 |
| commit | 23d880b127c346be631d2a9dbcef3bd5dff7d305 (patch) | |
| tree | d8211bd172e59b45c8bf115213d046a1801c64aa /src/librustc_driver | |
| parent | 8d16eeb8c9a8d6d85130b15ec9bd26df55773b12 (diff) | |
rustc_driver: factor out computing the exit code
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/lib.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 913ccf8e680..f8afaecf218 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1138,6 +1138,16 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported> }) } +/// Variant of `catch_fatal_errors` for the `interface::Result` return type +/// that also computes the exit code. +pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 { + let result = catch_fatal_errors(f).and_then(|result| result); + match result { + Ok(()) => EXIT_SUCCESS, + Err(_) => EXIT_FAILURE, + } +} + lazy_static! { static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = { let hook = panic::take_hook(); @@ -1233,7 +1243,7 @@ pub fn main() { init_rustc_env_logger(); let mut callbacks = TimePassesCallbacks::default(); install_ice_hook(); - let result = catch_fatal_errors(|| { + let exit_code = catch_with_exit_code(|| { let args = env::args_os() .enumerate() .map(|(i, arg)| { @@ -1246,12 +1256,7 @@ pub fn main() { }) .collect::<Vec<_>>(); run_compiler(&args, &mut callbacks, None, None) - }) - .and_then(|result| result); - let exit_code = match result { - Ok(_) => EXIT_SUCCESS, - Err(_) => EXIT_FAILURE, - }; + }); // The extra `\t` is necessary to align this label with the others. print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed()); process::exit(exit_code); |
