From 2bdd0755139cf7183d6c63bda16925d824640f10 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Thu, 2 Sep 2021 16:03:41 -0400 Subject: [PATCH 1/2] implement `Termination` for `Result` --- library/std/src/process.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index c9b21fcf9c6d2..d94b68967517d 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -106,6 +106,7 @@ mod tests; use crate::io::prelude::*; +use crate::convert::Infallible; use crate::ffi::OsStr; use crate::fmt; use crate::fs; @@ -2051,6 +2052,15 @@ impl Termination for Result { } } +#[unstable(feature = "termination_trait_lib", issue = "43301")] +impl Termination for Result { + fn report(self) -> i32 { + let Err(err) = self; + eprintln!("Error: {:?}", err); + ExitCode::FAILURE.report() + } +} + #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for ExitCode { #[inline] From 2433d3788e7b5fe7c095316fa38e462ff8093948 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Fri, 3 Sep 2021 11:24:25 -0400 Subject: [PATCH 2/2] simplify `impl Termination for Result` Co-authored-by: Konrad Borowski --- library/std/src/process.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index d94b68967517d..4f67cd88652e0 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2056,8 +2056,7 @@ impl Termination for Result { impl Termination for Result { fn report(self) -> i32 { let Err(err) = self; - eprintln!("Error: {:?}", err); - ExitCode::FAILURE.report() + Err::(err).report() } }