Skip to content

Commit b43fc1e

Browse files
authored
Rollup merge of rust-lang#106425 - ijackson:exit-status-default, r=dtolnay
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.
2 parents bf62436 + 1f1d49a commit b43fc1e

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

library/std/src/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ impl From<fs::File> for Stdio {
15281528
// vs `_exit`. Naming of Unix system calls is not standardised across Unices, so terminology is a
15291529
// matter of convention and tradition. For clarity we usually speak of `exit`, even when we might
15301530
// mean an underlying system call such as `_exit`.
1531-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
1531+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
15321532
#[stable(feature = "process", since = "1.0.0")]
15331533
pub struct ExitStatus(imp::ExitStatus);
15341534

library/std/src/sys/unix/process/process_fuchsia.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl Process {
235235
}
236236
}
237237

238-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
238+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
239239
pub struct ExitStatus(i64);
240240

241241
impl ExitStatus {

library/std/src/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl Process {
800800
//
801801
// This is not actually an "exit status" in Unix terminology. Rather, it is a "wait status".
802802
// See the discussion in comments and doc comments for `std::process::ExitStatus`.
803-
#[derive(PartialEq, Eq, Clone, Copy)]
803+
#[derive(PartialEq, Eq, Clone, Copy, Default)]
804804
pub struct ExitStatus(c_int);
805805

806806
impl fmt::Debug for ExitStatus {

library/std/src/sys/unix/process/process_unsupported.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Process {
5555
}
5656
}
5757

58-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
58+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
5959
pub struct ExitStatus(c_int);
6060

6161
impl ExitStatus {

library/std/src/sys/unix/process/process_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Process {
179179
}
180180

181181
/// Unix exit statuses
182-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
182+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
183183
pub struct ExitStatus(c_int);
184184

185185
impl ExitStatus {

library/std/src/sys/unsupported/process.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -99,58 +99,59 @@ impl fmt::Debug for Command {
9999
}
100100
}
101101

102-
pub struct ExitStatus(!);
102+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
103+
#[non_exhaustive]
104+
pub struct ExitStatus();
103105

104106
impl ExitStatus {
105107
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
106-
self.0
108+
Ok(())
107109
}
108110

109111
pub fn code(&self) -> Option<i32> {
110-
self.0
112+
Some(0)
111113
}
112114
}
113115

114-
impl Clone for ExitStatus {
115-
fn clone(&self) -> ExitStatus {
116-
self.0
116+
impl fmt::Display for ExitStatus {
117+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118+
write!(f, "<dummy exit status>")
117119
}
118120
}
119121

120-
impl Copy for ExitStatus {}
122+
pub struct ExitStatusError(!);
121123

122-
impl PartialEq for ExitStatus {
123-
fn eq(&self, _other: &ExitStatus) -> bool {
124+
impl Clone for ExitStatusError {
125+
fn clone(&self) -> ExitStatusError {
124126
self.0
125127
}
126128
}
127129

128-
impl Eq for ExitStatus {}
130+
impl Copy for ExitStatusError {}
129131

130-
impl fmt::Debug for ExitStatus {
131-
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
132+
impl PartialEq for ExitStatusError {
133+
fn eq(&self, _other: &ExitStatusError) -> bool {
132134
self.0
133135
}
134136
}
135137

136-
impl fmt::Display for ExitStatus {
138+
impl Eq for ExitStatusError {}
139+
140+
impl fmt::Debug for ExitStatusError {
137141
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
138142
self.0
139143
}
140144
}
141145

142-
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
143-
pub struct ExitStatusError(ExitStatus);
144-
145146
impl Into<ExitStatus> for ExitStatusError {
146147
fn into(self) -> ExitStatus {
147-
self.0.0
148+
self.0
148149
}
149150
}
150151

151152
impl ExitStatusError {
152153
pub fn code(self) -> Option<NonZeroI32> {
153-
self.0.0
154+
self.0
154155
}
155156
}
156157

library/std/src/sys/windows/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl Process {
652652
}
653653
}
654654

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

658658
impl ExitStatus {

0 commit comments

Comments
 (0)