Skip to content

Commit

Permalink
Rollup merge of rust-lang#48497 - scottmcm:more-restricted-terminatio…
Browse files Browse the repository at this point in the history
…n, r=nikomatsakis

Restrict the Termination impls to simplify stabilization

Make a minimal commitment in preparation for stabilization.  More impls, or broader ones, are likely in future, but are not necessary at this time and are more controversial.

cc rust-lang#48453 (comment)
r? @nikomatsakis
  • Loading branch information
kennytm authored Feb 28, 2018
2 parents a3fecfb + e20f7b2 commit d3fee34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,15 @@ impl fmt::Display for ExitStatus {
}
}

/// This is ridiculously unstable, as it's a completely-punted-upon part
/// of the `?`-in-`main` RFC. It's here only to allow experimenting with
/// returning a code directly from main. It will definitely change
/// drastically before being stabilized, if it doesn't just get deleted.
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
pub struct ExitCode(pub i32);

impl Child {
/// Forces the child to exit. This is equivalent to sending a
/// SIGKILL on unix platforms.
Expand Down Expand Up @@ -1428,7 +1437,7 @@ impl Termination for () {
}

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

#[unstable(feature = "termination_trait_lib", issue = "43301")]
impl Termination for ! {
fn report(self) -> i32 { unreachable!(); }
fn report(self) -> i32 { self }
}

#[unstable(feature = "termination_trait_lib", issue = "43301")]
impl Termination for bool {
impl<E: fmt::Debug> Termination for Result<!, E> {
fn report(self) -> i32 {
if self { exit::SUCCESS } else { exit::FAILURE }
let Err(err) = self;
eprintln!("Error: {:?}", err);
exit::FAILURE
}
}

#[unstable(feature = "termination_trait_lib", issue = "43301")]
impl Termination for i32 {
impl Termination for ExitCode {
fn report(self) -> i32 {
self
let ExitCode(code) = self;
code
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// except according to those terms.

#![feature(termination_trait)]
#![feature(process_exitcode_placeholder)]

fn main() -> i32 {
0
use std::process::ExitCode;

fn main() -> ExitCode {
ExitCode(0)
}

0 comments on commit d3fee34

Please sign in to comment.