Skip to content

Commit 848a38a

Browse files
committed
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. The Display impls are fixed, 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.) Signed-off-by: Ian Jackson <[email protected]>
1 parent 47ab5f7 commit 848a38a

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
@@ -607,9 +607,15 @@ impl Process {
607607
}
608608

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

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

686-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
692+
#[derive(PartialEq, Eq, Clone, Copy)]
687693
pub struct ExitStatusError(NonZero_c_int);
688694

689695
impl Into<ExitStatus> for ExitStatusError {
@@ -692,6 +698,12 @@ impl Into<ExitStatus> for ExitStatusError {
692698
}
693699
}
694700

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

0 commit comments

Comments
 (0)