Skip to content

Commit e8f03b9

Browse files
committed
Auto merge of #47544 - U007D:master, r=nikomatsakis
Relax termination_trait's error bound As per [this conversation](https://github.com/withoutboats/failure/issues/130#issuecomment-358572413) with @withoutboats and @bkchr
2 parents 5313e87 + 7948afd commit e8f03b9

11 files changed

+77
-18
lines changed

src/libstd/termination.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use error::Error;
11+
use fmt::Debug;
1212
#[cfg(target_arch = "wasm32")]
1313
mod exit {
1414
pub const SUCCESS: i32 = 0;
@@ -45,27 +45,18 @@ impl Termination for () {
4545
}
4646

4747
#[unstable(feature = "termination_trait", issue = "43301")]
48-
impl<T: Termination, E: Error> Termination for Result<T, E> {
48+
impl<T: Termination, E: Debug> Termination for Result<T, E> {
4949
fn report(self) -> i32 {
5050
match self {
5151
Ok(val) => val.report(),
5252
Err(err) => {
53-
print_error(err);
53+
eprintln!("Error: {:?}", err);
5454
exit::FAILURE
5555
}
5656
}
5757
}
5858
}
5959

60-
#[unstable(feature = "termination_trait", issue = "43301")]
61-
fn print_error<E: Error>(err: E) {
62-
eprintln!("Error: {}", err.description());
63-
64-
if let Some(ref err) = err.cause() {
65-
eprintln!("Caused by: {}", err.description());
66-
}
67-
}
68-
6960
#[unstable(feature = "termination_trait", issue = "43301")]
7061
impl Termination for ! {
7162
fn report(self) -> i32 { unreachable!(); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// must-compile-successfully
12+
// failure-status: 1
13+
14+
#![feature(termination_trait)]
15+
16+
use std::io::{Error, ErrorKind};
17+
18+
fn main() -> Result<(), Box<Error>> {
19+
Err(Box::new(Error::new(ErrorKind::Other, "returned Box<Error> from main()")))
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(termination_trait)]
12+
13+
use std::io::Error;
14+
15+
fn main() -> Result<(), Box<Error>> {
16+
Ok(())
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(termination_trait)]
12+
13+
use std::io::Error;
14+
15+
fn main() -> Result<(), Box<Error>> {
16+
Ok(())
17+
}

src/tools/compiletest/src/header.rs

+13
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub struct TestProps {
232232
// customized normalization rules
233233
pub normalize_stdout: Vec<(String, String)>,
234234
pub normalize_stderr: Vec<(String, String)>,
235+
pub failure_status: i32,
235236
}
236237

237238
impl TestProps {
@@ -260,6 +261,7 @@ impl TestProps {
260261
run_pass: false,
261262
normalize_stdout: vec![],
262263
normalize_stderr: vec![],
264+
failure_status: 101,
263265
}
264266
}
265267

@@ -383,6 +385,10 @@ impl TestProps {
383385
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
384386
self.normalize_stderr.push(rule);
385387
}
388+
389+
if let Some(code) = config.parse_failure_status(ln) {
390+
self.failure_status = code;
391+
}
386392
});
387393

388394
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
@@ -488,6 +494,13 @@ impl Config {
488494
self.parse_name_directive(line, "pretty-compare-only")
489495
}
490496

497+
fn parse_failure_status(&self, line: &str) -> Option<i32> {
498+
match self.parse_name_value_directive(line, "failure-status") {
499+
Some(code) => code.trim().parse::<i32>().ok(),
500+
_ => None,
501+
}
502+
}
503+
491504
fn parse_must_compile_successfully(&self, line: &str) -> bool {
492505
self.parse_name_directive(line, "must-compile-successfully")
493506
}

src/tools/compiletest/src/runtest.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,14 @@ impl<'test> TestCx<'test> {
295295
}
296296

297297
fn check_correct_failure_status(&self, proc_res: &ProcRes) {
298-
// The value the rust runtime returns on failure
299-
const RUST_ERR: i32 = 101;
300-
if proc_res.status.code() != Some(RUST_ERR) {
298+
let expected_status = Some(self.props.failure_status);
299+
let received_status = proc_res.status.code();
300+
301+
if expected_status != received_status {
301302
self.fatal_proc_rec(
302-
&format!("failure produced the wrong error: {}", proc_res.status),
303+
&format!("Error: expected failure status ({:?}) but received status {:?}.",
304+
expected_status,
305+
received_status),
303306
proc_res,
304307
);
305308
}
@@ -320,7 +323,6 @@ impl<'test> TestCx<'test> {
320323
);
321324

322325
let proc_res = self.exec_compiled_test();
323-
324326
if !proc_res.status.success() {
325327
self.fatal_proc_rec("test run failed!", &proc_res);
326328
}
@@ -499,7 +501,6 @@ impl<'test> TestCx<'test> {
499501
expected,
500502
actual
501503
);
502-
panic!();
503504
}
504505
}
505506

0 commit comments

Comments
 (0)