Repository navigation
Return ExitCode from main instead of calling process::exit - #17977
Conversation
|
Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews. In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews. |
| let code = exit_status.code().unwrap_or(-1); | ||
| cfg_select! { | ||
| // Unlike unix platforms, Windows uses the full 32-bits for exit codes. | ||
| windows => { | ||
| use std::os::windows::process::ExitCodeExt; | ||
| ExitCode::from_raw(code as u32) | ||
| }, | ||
| _ => ExitCode::from(code as u8), | ||
| } |
There was a problem hiding this comment.
This is the part I'm least happy with. But I am working on having the standard library provide a built-in conversion from ExitStatus to ExitCode. So hopefully it can eventually be replaced.
|
do note that CI has some complaints that will need to be fixed ^^ |
This comment has been minimized.
This comment has been minimized.
969e544 to
9fc54bf
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
9fc54bf to
f2dc14c
Compare
Thanks, fixed and rebased! |
f2dc14c to
f7a47cd
Compare
| @@ -1,54 +1,43 @@ | |||
| // We need this feature as it changes `dylib` linking behavior and allows us to link to | |||
| // `rustc_driver`. | |||
| // We need this feature as it changes `dylib` linking behavior. | |||
There was a problem hiding this comment.
Oh I really like not needing rustc_driver here anymore
| match writeln!(&mut anstream::stdout().lock(), "{}", help_message()) { | ||
| Ok(()) => ExitCode::SUCCESS, | ||
| Err(_) => ExitCode::FAILURE, |
There was a problem hiding this comment.
Can we use the Termination trait here?
| match writeln!(&mut anstream::stdout().lock(), "{}", help_message()) { | |
| Ok(()) => ExitCode::SUCCESS, | |
| Err(_) => ExitCode::FAILURE, | |
| writeln!(&mut anstream::stdout().lock(), "{}", help_message()).report() |
| match writeln!(&mut anstream::stdout().lock(), "{version_info}") { | ||
| Ok(()) => ExitCode::SUCCESS, | ||
| Err(_) => ExitCode::FAILURE, |
|
I've now made use of |
4e52a5a to
a0b74aa
Compare
changelog: none
This replaces uses of
process::exitin main with returningExitCodefrom main.process::exitis fraught, it doesn't run local drops and many not run thread local drops. It also has potential soundness issues (e.g. rust-lang/rust#126600).To be clear, I do not think clippy is affected by any issues but it'd be good to follow best practice, especially as things may evolve in the future. And as a side-effect this does provide more descriptive names for the common success and failure exit codes.
This PR does not change the
lintcheckorclippy_devcrates but I might follow up on that if this is accepted.