diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-10-03 23:13:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-03 23:13:18 -0700 |
| commit | e4d257e1d359cb0ec25f7a38964eef8a19d7ae71 (patch) | |
| tree | 8f64ccb1f17884c6cc3ecde80afa01b286f45ae8 /library/std/src/sys/unix/process/process_unix.rs | |
| parent | f2ec71fe74ca9db59dbcc43983d689ca31139779 (diff) | |
| parent | 848a38ac9d9bc956cded893bdd55e1171a2706dd (diff) | |
| download | rust-e4d257e1d359cb0ec25f7a38964eef8a19d7ae71.tar.gz rust-e4d257e1d359cb0ec25f7a38964eef8a19d7ae71.zip | |
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
Diffstat (limited to 'library/std/src/sys/unix/process/process_unix.rs')
| -rw-r--r-- | library/std/src/sys/unix/process/process_unix.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index c4215e2c78d..8c33051cfa4 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -606,9 +606,15 @@ impl Process { } /// 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) @@ -682,7 +688,7 @@ impl fmt::Display for ExitStatus { } } -#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[derive(PartialEq, Eq, Clone, Copy)] pub struct ExitStatusError(NonZero_c_int); impl Into<ExitStatus> for ExitStatusError { @@ -691,6 +697,12 @@ impl Into<ExitStatus> for ExitStatusError { } } +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()) |
