Skip to content

Commit e20f7b2

Browse files
committed
Restrict the Termination impls to simplify stabilization
Make a minimal commitment for stabilization. More impls are likely in future, but are not necessary at this time.
1 parent 026339e commit e20f7b2

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/libstd/process.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,15 @@ impl fmt::Display for ExitStatus {
10801080
}
10811081
}
10821082

1083+
/// This is ridiculously unstable, as it's a completely-punted-upon part
1084+
/// of the `?`-in-`main` RFC. It's here only to allow experimenting with
1085+
/// returning a code directly from main. It will definitely change
1086+
/// drastically before being stabilized, if it doesn't just get deleted.
1087+
#[doc(hidden)]
1088+
#[derive(Clone, Copy, Debug)]
1089+
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
1090+
pub struct ExitCode(pub i32);
1091+
10831092
impl Child {
10841093
/// Forces the child to exit. This is equivalent to sending a
10851094
/// SIGKILL on unix platforms.
@@ -1428,7 +1437,7 @@ impl Termination for () {
14281437
}
14291438

14301439
#[unstable(feature = "termination_trait_lib", issue = "43301")]
1431-
impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
1440+
impl<E: fmt::Debug> Termination for Result<(), E> {
14321441
fn report(self) -> i32 {
14331442
match self {
14341443
Ok(val) => val.report(),
@@ -1442,20 +1451,23 @@ impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
14421451

14431452
#[unstable(feature = "termination_trait_lib", issue = "43301")]
14441453
impl Termination for ! {
1445-
fn report(self) -> i32 { unreachable!(); }
1454+
fn report(self) -> i32 { self }
14461455
}
14471456

14481457
#[unstable(feature = "termination_trait_lib", issue = "43301")]
1449-
impl Termination for bool {
1458+
impl<E: fmt::Debug> Termination for Result<!, E> {
14501459
fn report(self) -> i32 {
1451-
if self { exit::SUCCESS } else { exit::FAILURE }
1460+
let Err(err) = self;
1461+
eprintln!("Error: {:?}", err);
1462+
exit::FAILURE
14521463
}
14531464
}
14541465

14551466
#[unstable(feature = "termination_trait_lib", issue = "43301")]
1456-
impl Termination for i32 {
1467+
impl Termination for ExitCode {
14571468
fn report(self) -> i32 {
1458-
self
1469+
let ExitCode(code) = self;
1470+
code
14591471
}
14601472
}
14611473

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-i32.rs renamed to src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-exitcode.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
// except according to those terms.
1010

1111
#![feature(termination_trait)]
12+
#![feature(process_exitcode_placeholder)]
1213

13-
fn main() -> i32 {
14-
0
14+
use std::process::ExitCode;
15+
16+
fn main() -> ExitCode {
17+
ExitCode(0)
1518
}

0 commit comments

Comments
 (0)