Skip to content

Commit

Permalink
Rollup merge of rust-lang#106425 - ijackson:exit-status-default, r=dt…
Browse files Browse the repository at this point in the history
…olnay

Make ExitStatus implement Default

And, necessarily, make it inhabited even on platforms without processes.

I noticed while preparing rust-lang/rfcs#3362 that there was no way for anyone to construct an `ExitStatus`.

This would be insta-stable so needs an FCP.
  • Loading branch information
matthiaskrgr committed Aug 8, 2023
2 parents bf62436 + 1f1d49a commit b43fc1e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ impl From<fs::File> for Stdio {
// vs `_exit`. Naming of Unix system calls is not standardised across Unices, so terminology is a
// matter of convention and tradition. For clarity we usually speak of `exit`, even when we might
// mean an underlying system call such as `_exit`.
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
#[stable(feature = "process", since = "1.0.0")]
pub struct ExitStatus(imp::ExitStatus);

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Process {
}
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(i64);

impl ExitStatus {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl Process {
//
// This is not actually an "exit status" in Unix terminology. Rather, it is a "wait status".
// See the discussion in comments and doc comments for `std::process::ExitStatus`.
#[derive(PartialEq, Eq, Clone, Copy)]
#[derive(PartialEq, Eq, Clone, Copy, Default)]
pub struct ExitStatus(c_int);

impl fmt::Debug for ExitStatus {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Process {
}
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c_int);

impl ExitStatus {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Process {
}

/// Unix exit statuses
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c_int);

impl ExitStatus {
Expand Down
37 changes: 19 additions & 18 deletions library/std/src/sys/unsupported/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,59 @@ impl fmt::Debug for Command {
}
}

pub struct ExitStatus(!);
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct ExitStatus();

impl ExitStatus {
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
self.0
Ok(())
}

pub fn code(&self) -> Option<i32> {
self.0
Some(0)
}
}

impl Clone for ExitStatus {
fn clone(&self) -> ExitStatus {
self.0
impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<dummy exit status>")
}
}

impl Copy for ExitStatus {}
pub struct ExitStatusError(!);

impl PartialEq for ExitStatus {
fn eq(&self, _other: &ExitStatus) -> bool {
impl Clone for ExitStatusError {
fn clone(&self) -> ExitStatusError {
self.0
}
}

impl Eq for ExitStatus {}
impl Copy for ExitStatusError {}

impl fmt::Debug for ExitStatus {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl PartialEq for ExitStatusError {
fn eq(&self, _other: &ExitStatusError) -> bool {
self.0
}
}

impl fmt::Display for ExitStatus {
impl Eq for ExitStatusError {}

impl fmt::Debug for ExitStatusError {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0
}
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct ExitStatusError(ExitStatus);

impl Into<ExitStatus> for ExitStatusError {
fn into(self) -> ExitStatus {
self.0.0
self.0
}
}

impl ExitStatusError {
pub fn code(self) -> Option<NonZeroI32> {
self.0.0
self.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl Process {
}
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c::DWORD);

impl ExitStatus {
Expand Down

0 comments on commit b43fc1e

Please sign in to comment.