Use ExitCode when returning from main in miri

This commit is contained in:
Chris Denton 2025-12-26 18:44:02 +00:00
parent 6d36c8a5fc
commit 0c432af701
No known key found for this signature in database
GPG key ID: 713472F2F45627DE

View file

@ -39,6 +39,7 @@ mod log;
use std::env;
use std::num::{NonZero, NonZeroI32};
use std::ops::Range;
use std::process::ExitCode;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::Once;
@ -404,7 +405,11 @@ fn run_compiler_and_exit(
// Invoke compiler, catch any unwinding panics and handle return code.
let exit_code =
rustc_driver::catch_with_exit_code(move || rustc_driver::run_compiler(args, callbacks));
exit(exit_code)
exit(if exit_code == ExitCode::SUCCESS {
rustc_driver::EXIT_SUCCESS
} else {
rustc_driver::EXIT_FAILURE
})
}
/// Parses a comma separated list of `T` from the given string:
@ -434,7 +439,7 @@ fn parse_range(val: &str) -> Result<Range<u32>, &'static str> {
Ok(from..to)
}
fn main() {
fn main() -> ExitCode {
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
// Snapshot a copy of the environment before `rustc` starts messing with it.
@ -449,9 +454,7 @@ fn main() {
if crate_kind == "host" {
// For host crates like proc macros and build scripts, we are an entirely normal rustc.
// These eventually produce actual binaries and never run in Miri.
match rustc_driver::main() {
// Empty match proves this function will never return.
}
return rustc_driver::main();
} else if crate_kind != "target" {
panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}")
};