about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-02-22 17:36:55 -0500
committerNiko Matsakis <niko@alum.mit.edu>2018-02-22 17:57:08 -0500
commit5f1e78f19ad40c6265a200b41c772c321b8b08cd (patch)
treecfa88d292f71b6252f9864b4ff731bcb71424e23
parente446f706a89e3d5c26c01318bd70904d492ab8b2 (diff)
downloadrust-5f1e78f19ad40c6265a200b41c772c321b8b08cd.tar.gz
rust-5f1e78f19ad40c6265a200b41c772c321b8b08cd.zip
move Termination trait to std::process
-rw-r--r--src/libstd/lib.rs4
-rw-r--r--src/libstd/process.rs67
-rw-r--r--src/libstd/rt.rs2
-rw-r--r--src/libstd/termination.rs81
-rw-r--r--src/libtest/lib.rs2
-rw-r--r--src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs2
-rw-r--r--src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs2
7 files changed, 71 insertions, 89 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index b247d121648..bdda7416336 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -502,10 +502,6 @@ mod memchr;
 // compiler
 pub mod rt;
 
-// The trait to support returning arbitrary types in the main function
-#[unstable(feature = "termination_trait", issue = "43301")]
-pub mod termination;
-
 // Include a number of private modules that exist solely to provide
 // the rustdoc documentation for primitive types. Using `include!`
 // because rustdoc only looks for these modules at the crate level.
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 9b2f815b713..e25599b8bd8 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -1392,6 +1392,73 @@ pub fn id() -> u32 {
     ::sys::os::getpid()
 }
 
+#[cfg(target_arch = "wasm32")]
+mod exit {
+    pub const SUCCESS: i32 = 0;
+    pub const FAILURE: i32 = 1;
+}
+#[cfg(not(target_arch = "wasm32"))]
+mod exit {
+    use libc;
+    pub const SUCCESS: i32 = libc::EXIT_SUCCESS;
+    pub const FAILURE: i32 = libc::EXIT_FAILURE;
+}
+
+/// A trait for implementing arbitrary return types in the `main` function.
+///
+/// The c-main function only supports to return integers as return type.
+/// So, every type implementing the `Termination` trait has to be converted
+/// to an integer.
+///
+/// The default implementations are returning `libc::EXIT_SUCCESS` to indicate
+/// a successful execution. In case of a failure, `libc::EXIT_FAILURE` is returned.
+#[cfg_attr(not(test), lang = "termination")]
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+#[rustc_on_unimplemented =
+  "`main` can only return types that implement {Termination}, not `{Self}`"]
+pub trait Termination {
+    /// Is called to get the representation of the value as status code.
+    /// This status code is returned to the operating system.
+    fn report(self) -> i32;
+}
+
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+impl Termination for () {
+    fn report(self) -> i32 { exit::SUCCESS }
+}
+
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
+    fn report(self) -> i32 {
+        match self {
+            Ok(val) => val.report(),
+            Err(err) => {
+                eprintln!("Error: {:?}", err);
+                exit::FAILURE
+            }
+        }
+    }
+}
+
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+impl Termination for ! {
+    fn report(self) -> i32 { unreachable!(); }
+}
+
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+impl Termination for bool {
+    fn report(self) -> i32 {
+        if self { exit::SUCCESS } else { exit::FAILURE }
+    }
+}
+
+#[unstable(feature = "termination_trait_lib", issue = "43301")]
+impl Termination for i32 {
+    fn report(self) -> i32 {
+        self
+    }
+}
+
 #[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
 mod tests {
     use io::prelude::*;
diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs
index 9dbaf784f89..e1392762a59 100644
--- a/src/libstd/rt.rs
+++ b/src/libstd/rt.rs
@@ -68,7 +68,7 @@ fn lang_start_internal(main: &(Fn() -> i32 + Sync + ::panic::RefUnwindSafe),
 
 #[cfg(not(test))]
 #[lang = "start"]
-fn lang_start<T: ::termination::Termination + 'static>
+fn lang_start<T: ::process::Termination + 'static>
     (main: fn() -> T, argc: isize, argv: *const *const u8) -> isize
 {
     lang_start_internal(&move || main().report(), argc, argv)
diff --git a/src/libstd/termination.rs b/src/libstd/termination.rs
deleted file mode 100644
index 203870766a9..00000000000
--- a/src/libstd/termination.rs
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2017 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Defines the meaning of the return value from `main`, and hence
-//! controls what happens in a Rust program after `main` returns.
-
-use fmt::Debug;
-
-#[cfg(target_arch = "wasm32")]
-mod exit {
-    pub const SUCCESS: i32 = 0;
-    pub const FAILURE: i32 = 1;
-}
-#[cfg(not(target_arch = "wasm32"))]
-mod exit {
-    use libc;
-    pub const SUCCESS: i32 = libc::EXIT_SUCCESS;
-    pub const FAILURE: i32 = libc::EXIT_FAILURE;
-}
-
-/// A trait for implementing arbitrary return types in the `main` function.
-///
-/// The c-main function only supports to return integers as return type.
-/// So, every type implementing the `Termination` trait has to be converted
-/// to an integer.
-///
-/// The default implementations are returning `libc::EXIT_SUCCESS` to indicate
-/// a successful execution. In case of a failure, `libc::EXIT_FAILURE` is returned.
-#[cfg_attr(not(test), lang = "termination")]
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-#[rustc_on_unimplemented =
-  "`main` can only return types that implement {Termination}, not `{Self}`"]
-pub trait Termination {
-    /// Is called to get the representation of the value as status code.
-    /// This status code is returned to the operating system.
-    fn report(self) -> i32;
-}
-
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-impl Termination for () {
-    fn report(self) -> i32 { exit::SUCCESS }
-}
-
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-impl<T: Termination, E: Debug> Termination for Result<T, E> {
-    fn report(self) -> i32 {
-        match self {
-            Ok(val) => val.report(),
-            Err(err) => {
-                eprintln!("Error: {:?}", err);
-                exit::FAILURE
-            }
-        }
-    }
-}
-
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-impl Termination for ! {
-    fn report(self) -> i32 { unreachable!(); }
-}
-
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-impl Termination for bool {
-    fn report(self) -> i32 {
-        if self { exit::SUCCESS } else { exit::FAILURE }
-    }
-}
-
-#[unstable(feature = "termination_trait_lib", issue = "43301")]
-impl Termination for i32 {
-    fn report(self) -> i32 {
-        self
-    }
-}
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 932952d649b..06a23cd8818 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -68,9 +68,9 @@ use std::io::prelude::*;
 use std::io;
 use std::iter::repeat;
 use std::path::PathBuf;
+use std::process::Termination;
 use std::sync::mpsc::{channel, Sender};
 use std::sync::{Arc, Mutex};
-use std::termination::Termination;
 use std::thread;
 use std::time::{Instant, Duration};
 use std::borrow::Cow;
diff --git a/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
index 2da51851952..93e2561adf7 100644
--- a/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
+++ b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
@@ -10,6 +10,6 @@
 #![feature(termination_trait)]
 
 fn main() -> char {
-//~^ ERROR: the trait bound `char: std::termination::Termination` is not satisfied
+//~^ ERROR: the trait bound `char: std::process::Termination` is not satisfied
     ' '
 }
diff --git a/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
index fac60d6d399..e87e0ceebf1 100644
--- a/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
+++ b/src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
@@ -12,6 +12,6 @@
 
 struct ReturnType {}
 
-fn main() -> ReturnType { //~ ERROR `ReturnType: std::termination::Termination` is not satisfied
+fn main() -> ReturnType { //~ ERROR `ReturnType: std::process::Termination` is not satisfied
     ReturnType {}
 }