Rollup merge of #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 https://github.com/rust-lang/rfcs/pull/3362 that there was no way for anyone to construct an `ExitStatus`.

This would be insta-stable so needs an FCP.
This commit is contained in:
Matthias Krüger 2023-08-08 21:44:41 +02:00 committed by GitHub
commit b3550891e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 36 deletions

View File

@ -1528,7 +1528,7 @@ fn from(file: fs::File) -> 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);

View File

@ -235,7 +235,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
}
}
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(i64);
impl ExitStatus {

View File

@ -800,7 +800,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
//
// 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 {

View File

@ -55,7 +55,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
}
}
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c_int);
impl ExitStatus {

View File

@ -179,7 +179,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
}
/// Unix exit statuses
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c_int);
impl ExitStatus {

View File

@ -99,58 +99,59 @@ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
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
}
}
impl Clone for ExitStatus {
fn clone(&self) -> ExitStatus {
self.0
}
}
impl Copy for ExitStatus {}
impl PartialEq for ExitStatus {
fn eq(&self, _other: &ExitStatus) -> bool {
self.0
}
}
impl Eq for ExitStatus {}
impl fmt::Debug for ExitStatus {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0
Some(0)
}
}
impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<dummy exit status>")
}
}
pub struct ExitStatusError(!);
impl Clone for ExitStatusError {
fn clone(&self) -> ExitStatusError {
self.0
}
}
impl Copy for ExitStatusError {}
impl PartialEq for ExitStatusError {
fn eq(&self, _other: &ExitStatusError) -> bool {
self.0
}
}
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
}
}

View File

@ -652,7 +652,7 @@ pub fn into_handle(self) -> Handle {
}
}
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct ExitStatus(c::DWORD);
impl ExitStatus {