diff options
| author | bors <bors@rust-lang.org> | 2021-05-18 08:01:32 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-18 08:01:32 +0000 | 
| commit | 25a277f03df7e44643ddfcc240d034409cb2f505 (patch) | |
| tree | c4f00d62c473f44d09ccb147ead2775ce280628d /library/std/src/os/unix/process.rs | |
| parent | 5f10d310f475b3ba583b9c590b8d19f6c2fde28f (diff) | |
| parent | 26c782b8e7f939a00f889dfb3f1e969fc8f8c79d (diff) | |
| download | rust-25a277f03df7e44643ddfcc240d034409cb2f505.tar.gz rust-25a277f03df7e44643ddfcc240d034409cb2f505.zip | |
Auto merge of #82973 - ijackson:exitstatuserror, r=yaahc
Provide ExitStatusError Closes #73125 In MR #81452 "Add #[must_use] to [...] process::ExitStatus" we concluded that the existing arrangements in are too awkward so adding that `#[must_use]` is blocked on improving the ergonomics. I wrote a mini-RFC-style discusion of the approach in https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741
Diffstat (limited to 'library/std/src/os/unix/process.rs')
| -rw-r--r-- | library/std/src/os/unix/process.rs | 53 | 
1 files changed, 46 insertions, 7 deletions
| diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index f014a3d7b25..3dc389b7582 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -201,22 +201,32 @@ impl CommandExt for process::Command { } } -/// Unix-specific extensions to [`process::ExitStatus`]. +/// Unix-specific extensions to [`process::ExitStatus`] and +/// [`ExitStatusError`](process::ExitStatusError). /// -/// On Unix, `ExitStatus` **does not necessarily represent an exit status**, as passed to the -/// `exit` system call or returned by [`ExitStatus::code()`](crate::process::ExitStatus::code). -/// It represents **any wait status**, as returned by one of the `wait` family of system calls. +/// On Unix, `ExitStatus` **does not necessarily represent an exit status**, as +/// passed to the `exit` system call or returned by +/// [`ExitStatus::code()`](crate::process::ExitStatus::code). It represents **any wait status** +/// as returned by one of the `wait` family of system +/// calls. /// -/// This is because a Unix wait status (a Rust `ExitStatus`) can represent a Unix exit status, but -/// can also represent other kinds of process event. +/// A Unix wait status (a Rust `ExitStatus`) can represent a Unix exit status, but can also +/// represent other kinds of process event. /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] pub trait ExitStatusExt: Sealed { - /// Creates a new `ExitStatus` from the raw underlying integer status value from `wait` + /// Creates a new `ExitStatus` or `ExitStatusError` from the raw underlying integer status + /// value from `wait` /// /// The value should be a **wait status, not an exit status**. + /// + /// # Panics + /// + /// Panics on an attempt to make an `ExitStatusError` from a wait status of `0`. + /// + /// Making an `ExitStatus` always succeds and never panics. #[stable(feature = "exit_status_from", since = "1.12.0")] fn from_raw(raw: i32) -> Self; @@ -278,6 +288,35 @@ impl ExitStatusExt for process::ExitStatus { } } +#[unstable(feature = "exit_status_error", issue = "84908")] +impl ExitStatusExt for process::ExitStatusError { + fn from_raw(raw: i32) -> Self { + process::ExitStatus::from_raw(raw) + .exit_ok() + .expect_err("<ExitStatusError as ExitStatusExt>::from_raw(0) but zero is not an error") + } + + fn signal(&self) -> Option<i32> { + self.into_status().signal() + } + + fn core_dumped(&self) -> bool { + self.into_status().core_dumped() + } + + fn stopped_signal(&self) -> Option<i32> { + self.into_status().stopped_signal() + } + + fn continued(&self) -> bool { + self.into_status().continued() + } + + fn into_raw(self) -> i32 { + self.into_status().into_raw() + } +} + #[stable(feature = "process_extensions", since = "1.2.0")] impl FromRawFd for process::Stdio { #[inline] | 
