diff --git a/library/std/src/process.rs b/library/std/src/process.rs index e733766741d5..da8eee9030b9 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2140,16 +2140,6 @@ impl Termination for () { } } -#[stable(feature = "termination_trait_lib", since = "1.61.0")] -impl Termination for Result<(), E> { - fn report(self) -> ExitCode { - match self { - Ok(()) => ().report(), - Err(err) => Err::(err).report(), - } - } -} - #[stable(feature = "termination_trait_lib", since = "1.61.0")] impl Termination for ! { fn report(self) -> ExitCode { @@ -2158,21 +2148,9 @@ impl Termination for ! { } #[stable(feature = "termination_trait_lib", since = "1.61.0")] -impl Termination for Result { +impl Termination for Infallible { fn report(self) -> ExitCode { - let Err(err) = self; - // Ignore error if the write fails, for example because stderr is - // already closed. There is not much point panicking at this point. - let _ = writeln!(io::stderr(), "Error: {err:?}"); - ExitCode::FAILURE - } -} - -#[stable(feature = "termination_trait_lib", since = "1.61.0")] -impl Termination for Result { - fn report(self) -> ExitCode { - let Err(err) = self; - Err::(err).report() + match self {} } } @@ -2183,3 +2161,18 @@ impl Termination for ExitCode { self } } + +#[stable(feature = "termination_trait_lib", since = "1.61.0")] +impl Termination for Result { + fn report(self) -> ExitCode { + match self { + Ok(val) => val.report(), + Err(err) => { + // Ignore error if the write fails, for example because stderr is + // already closed. There is not much point panicking at this point. + let _ = writeln!(io::stderr(), "Error: {err:?}"); + ExitCode::FAILURE + } + } + } +}