Skip to content

Commit e4d257e

Browse files
authored
Rollup merge of #88305 - ijackson:exitstatus-debug, r=dtolnay
Manual Debug for Unix ExitCode ExitStatus ExitStatusError These structs have misleading names. An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status. These misleading names appear in the `Debug` output. The `Display` impls on Unix have been improved, but the `Debug` impls are still misleading, as reported in #74832. Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable. (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.) After this change, this program ``` #![feature(exit_status_error)] fn main(){ let x = std::process::Command::new("false").status().unwrap(); dbg!(x.exit_ok()); eprintln!("x={:?}",x); } ``` produces this output ``` [src/main.rs:4] x.exit_ok() = Err( ExitStatusError( unix_wait_status( 256, ), ), ) x=ExitStatus(unix_wait_status(256)) ``` Closes #74832
2 parents f2ec71f + 848a38a commit e4d257e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

library/std/src/sys/unix/process/process_common.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,15 @@ impl fmt::Debug for Command {
457457
}
458458
}
459459

460-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
460+
#[derive(PartialEq, Eq, Clone, Copy)]
461461
pub struct ExitCode(u8);
462462

463+
impl fmt::Debug for ExitCode {
464+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
465+
f.debug_tuple("unix_exit_status").field(&self.0).finish()
466+
}
467+
}
468+
463469
impl ExitCode {
464470
pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
465471
pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);

library/std/src/sys/unix/process/process_unix.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,15 @@ impl Process {
606606
}
607607

608608
/// Unix exit statuses
609-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
609+
#[derive(PartialEq, Eq, Clone, Copy)]
610610
pub struct ExitStatus(c_int);
611611

612+
impl fmt::Debug for ExitStatus {
613+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
614+
f.debug_tuple("unix_wait_status").field(&self.0).finish()
615+
}
616+
}
617+
612618
impl ExitStatus {
613619
pub fn new(status: c_int) -> ExitStatus {
614620
ExitStatus(status)
@@ -682,7 +688,7 @@ impl fmt::Display for ExitStatus {
682688
}
683689
}
684690

685-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
691+
#[derive(PartialEq, Eq, Clone, Copy)]
686692
pub struct ExitStatusError(NonZero_c_int);
687693

688694
impl Into<ExitStatus> for ExitStatusError {
@@ -691,6 +697,12 @@ impl Into<ExitStatus> for ExitStatusError {
691697
}
692698
}
693699

700+
impl fmt::Debug for ExitStatusError {
701+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
702+
f.debug_tuple("unix_wait_status").field(&self.0).finish()
703+
}
704+
}
705+
694706
impl ExitStatusError {
695707
pub fn code(self) -> Option<NonZeroI32> {
696708
ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())

0 commit comments

Comments
 (0)