From c7f6af5359d472caaa8d6a74b017d0d8de296a0c Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Wed, 17 Jan 2018 15:04:19 -0800 Subject: [PATCH 1/5] Enabled failure crate compatibility by changing Termination's error trait bound from Error to Debug --- src/libstd/termination.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/libstd/termination.rs b/src/libstd/termination.rs index 93a913bb540b7..dc7fa53aab632 100644 --- a/src/libstd/termination.rs +++ b/src/libstd/termination.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use error::Error; +use fmt::Debug; #[cfg(target_arch = "wasm32")] mod exit { pub const SUCCESS: i32 = 0; @@ -45,27 +45,18 @@ impl Termination for () { } #[unstable(feature = "termination_trait", issue = "43301")] -impl Termination for Result { +impl Termination for Result { fn report(self) -> i32 { match self { Ok(val) => val.report(), Err(err) => { - print_error(err); + eprintln!("Error: {:?}", err); exit::FAILURE } } } } -#[unstable(feature = "termination_trait", issue = "43301")] -fn print_error(err: E) { - eprintln!("Error: {}", err.description()); - - if let Some(ref err) = err.cause() { - eprintln!("Caused by: {}", err.description()); - } -} - #[unstable(feature = "termination_trait", issue = "43301")] impl Termination for ! { fn report(self) -> i32 { unreachable!(); } From 87236c6ccd2df0022f7cd9ebf35080ca383a95e6 Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Thu, 18 Jan 2018 22:29:28 -0800 Subject: [PATCH 2/5] Added positive (Ok()) test for main -> Result<(), std::io::Error> --- ...termination-trait-for-result-box-error_ok.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/run-pass/termination-trait-for-result-box-error_ok.rs diff --git a/src/test/run-pass/termination-trait-for-result-box-error_ok.rs b/src/test/run-pass/termination-trait-for-result-box-error_ok.rs new file mode 100644 index 0000000000000..269ac451cf4d8 --- /dev/null +++ b/src/test/run-pass/termination-trait-for-result-box-error_ok.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(termination_trait)] + +use std::io::Error; + +fn main() -> Result<(), Box> { + Ok(()) +} From 82bc025f36dc81280c3295d79e8cc225184d2000 Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Fri, 19 Jan 2018 00:03:07 -0800 Subject: [PATCH 3/5] Added negative (Err()) test for main() -> Result<(), std::io::Error> --- ...rmination-trait-for-result-box-error_err.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-fail/termination-trait-for-result-box-error_err.rs diff --git a/src/test/run-fail/termination-trait-for-result-box-error_err.rs b/src/test/run-fail/termination-trait-for-result-box-error_err.rs new file mode 100644 index 0000000000000..8b61994f2b4ad --- /dev/null +++ b/src/test/run-fail/termination-trait-for-result-box-error_err.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:nonzero +#![feature(termination_trait)] + +use std::io::{Error, ErrorKind}; + +fn main() -> Result<(), Box> { + Err(Box::new(Error::new(ErrorKind::Other, "returned Box from main()"))) +} From 4230c51e92a0bf3b515a74b0d85af083f6114900 Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Fri, 19 Jan 2018 11:18:55 -0800 Subject: [PATCH 4/5] created negative (Err()) test for termination_trait; modified compiletest to support successful compile/non-panicking/non-zero exit code as a run-fail test scenario --- .../termination-trait-for-result-box-error_err.rs | 3 ++- src/tools/compiletest/src/runtest.rs | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/test/run-fail/termination-trait-for-result-box-error_err.rs b/src/test/run-fail/termination-trait-for-result-box-error_err.rs index 8b61994f2b4ad..3f4d75ecdd50b 100644 --- a/src/test/run-fail/termination-trait-for-result-box-error_err.rs +++ b/src/test/run-fail/termination-trait-for-result-box-error_err.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:nonzero +// must-compile-successfully + #![feature(termination_trait)] use std::io::{Error, ErrorKind}; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index efbe5e32fcd27..b145f4791a6f1 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -295,11 +295,10 @@ impl<'test> TestCx<'test> { } fn check_correct_failure_status(&self, proc_res: &ProcRes) { - // The value the rust runtime returns on failure - const RUST_ERR: i32 = 101; - if proc_res.status.code() != Some(RUST_ERR) { + if proc_res.status.success() { self.fatal_proc_rec( - &format!("failure produced the wrong error: {}", proc_res.status), + &format!("failure must not return success exit status! Returned status: {}", + proc_res.status), proc_res, ); } @@ -320,7 +319,6 @@ impl<'test> TestCx<'test> { ); let proc_res = self.exec_compiled_test(); - if !proc_res.status.success() { self.fatal_proc_rec("test run failed!", &proc_res); } @@ -500,7 +498,6 @@ impl<'test> TestCx<'test> { expected, actual ); - panic!(); } } From 65d5f0940404e68966fd44177966e597f8bded7d Mon Sep 17 00:00:00 2001 From: Brad Gibson Date: Fri, 19 Jan 2018 13:06:52 -0800 Subject: [PATCH 5/5] Removed unnecessary reporting of status variable --- src/tools/compiletest/src/runtest.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index b145f4791a6f1..4a63fb87fb417 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -297,8 +297,7 @@ impl<'test> TestCx<'test> { fn check_correct_failure_status(&self, proc_res: &ProcRes) { if proc_res.status.success() { self.fatal_proc_rec( - &format!("failure must not return success exit status! Returned status: {}", - proc_res.status), + &format!("failure must not return success (exit status 0)!"), proc_res, ); }