Skip to content

Commit 5cfe3db

Browse files
committed
Return std::process::ExitCode instead of exiting with std::process::exit
rust-lang/rust#77553 still exists on nightly-2025-01-30.
1 parent 37477de commit 5cfe3db

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/cli.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ pub(crate) fn merge_config_to_args(
473473
}
474474

475475
impl Args {
476-
pub(crate) fn parse() -> Result<Self> {
476+
pub(crate) fn parse() -> Result<Option<Self>> {
477477
const SUBCMD: &str = "llvm-cov";
478478

479479
// rustc/cargo args must be valid Unicode
@@ -775,15 +775,14 @@ impl Args {
775775
}
776776
Short('h') | Long("help") => {
777777
print!("{}", Subcommand::help_text(subcommand));
778-
std::process::exit(0);
778+
return Ok(None);
779779
}
780780
Short('V') | Long("version") => {
781781
if subcommand == Subcommand::None {
782782
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
783-
std::process::exit(0);
784-
} else {
785-
unexpected("--version", subcommand)?;
783+
return Ok(None);
786784
}
785+
unexpected("--version", subcommand)?
787786
}
788787

789788
// TODO: Currently, we are using a subdirectory of the target directory as
@@ -1235,7 +1234,7 @@ impl Args {
12351234
}
12361235
}
12371236

1238-
Ok(Self {
1237+
Ok(Some(Self {
12391238
subcommand,
12401239
cov: LlvmCovOptions {
12411240
json,
@@ -1300,7 +1299,7 @@ impl Args {
13001299
nextest_archive_file,
13011300
cargo_args,
13021301
rest,
1303-
})
1302+
}))
13041303
}
13051304
}
13061305

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{
1212
ffi::{OsStr, OsString},
1313
io::{self, BufRead as _, Read as _, Write as _},
1414
path::Path,
15+
process::ExitCode,
1516
time::SystemTime,
1617
};
1718

@@ -49,18 +50,20 @@ mod fs;
4950
mod metadata;
5051
mod regex_vec;
5152

52-
fn main() {
53+
fn main() -> ExitCode {
5354
term::init_coloring();
5455
if let Err(e) = try_main() {
5556
error!("{e:#}");
5657
}
5758
if term::error() || term::warn() && env::var_os("CARGO_LLVM_COV_DENY_WARNINGS").is_some() {
58-
std::process::exit(1)
59+
ExitCode::FAILURE
60+
} else {
61+
ExitCode::SUCCESS
5962
}
6063
}
6164

6265
fn try_main() -> Result<()> {
63-
let mut args = Args::parse()?;
66+
let Some(mut args) = Args::parse()? else { return Ok(()) };
6467
term::verbose::set(args.verbose != 0);
6568

6669
match args.subcommand {

0 commit comments

Comments
 (0)