]> git.lizzy.rs Git - rust.git/commitdiff
Manual Debug for Unix ExitCode ExitStatus ExitStatusError
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 24 Aug 2021 17:56:24 +0000 (18:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 24 Aug 2021 18:24:07 +0000 (19:24 +0100)
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 <ijackson@chiark.greenend.org.uk>
library/std/src/sys/unix/process/process_common.rs
library/std/src/sys/unix/process/process_unix.rs

index 7b261a302c33f280428799c576d940fc3c9f31b8..7ac2f9d8af75a139609b84d5cb47bd349f83c1a8 100644 (file)
@@ -457,9 +457,15 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub struct ExitCode(u8);
 
+impl fmt::Debug for ExitCode {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_tuple("unix_exit_status").field(&self.0).finish()
+    }
+}
+
 impl ExitCode {
     pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
     pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
index 12edf04a4e2e9f780db06dcbaf52ff972a774e4e..7b8230d89daa747dccbca6d4b8993414324ede17 100644 (file)
@@ -607,9 +607,15 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
 }
 
 /// Unix exit statuses
-#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub struct ExitStatus(c_int);
 
+impl fmt::Debug for ExitStatus {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_tuple("unix_wait_status").field(&self.0).finish()
+    }
+}
+
 impl ExitStatus {
     pub fn new(status: c_int) -> ExitStatus {
         ExitStatus(status)
@@ -683,7 +689,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub struct ExitStatusError(NonZero_c_int);
 
 impl Into<ExitStatus> for ExitStatusError {
@@ -692,6 +698,12 @@ fn into(self) -> ExitStatus {
     }
 }
 
+impl fmt::Debug for ExitStatusError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_tuple("unix_wait_status").field(&self.0).finish()
+    }
+}
+
 impl ExitStatusError {
     pub fn code(self) -> Option<NonZeroI32> {
         ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())