about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBastian Köcher <git@kchr.de>2017-12-24 00:15:38 +0100
committerBastian Köcher <git@kchr.de>2017-12-26 12:26:39 +0100
commit7dfec34a20af59e50f59f73799f471795a50eeb8 (patch)
treea0f595b8be8c28de02b030ee3a9a46ef0fb7fee5 /src/libstd
parentc2f22f01a9263870d33a26e988bb13b8f622ce7a (diff)
downloadrust-7dfec34a20af59e50f59f73799f471795a50eeb8.tar.gz
rust-7dfec34a20af59e50f59f73799f471795a50eeb8.zip
Split `lang_start` in two functions to reduce generated code
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/rt.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs
index 1fd7c270d19..27c20be7a9a 100644
--- a/src/libstd/rt.rs
+++ b/src/libstd/rt.rs
@@ -26,10 +26,11 @@
 // Reexport some of our utilities which are expected by other crates.
 pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
 
+// To reduce the generated code of the new `lang_start`, this function is doing
+// the real work.
 #[cfg(not(any(test, stage0)))]
-#[lang = "start"]
-fn lang_start<T: ::termination::Termination + 'static>
-    (main: fn() -> T, argc: isize, argv: *const *const u8) -> !
+fn lang_start_real<F>(main: F, argc: isize, argv: *const *const u8) -> !
+    where F: FnOnce() -> i32 + Send + ::panic::UnwindSafe + 'static
 {
     use panic;
     use sys;
@@ -59,16 +60,24 @@ fn lang_start<T: ::termination::Termination + 'static>
         // Let's run some code!
         #[cfg(feature = "backtrace")]
         let exit_code = panic::catch_unwind(|| {
-            ::sys_common::backtrace::__rust_begin_short_backtrace(move || main().report())
+            ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
         });
         #[cfg(not(feature = "backtrace"))]
-        let exit_code = panic::catch_unwind(move || main().report());
+        let exit_code = panic::catch_unwind(move || main());
 
         sys_common::cleanup();
         exit_code.unwrap_or(101)
     });
 }
 
+#[cfg(not(any(test, stage0)))]
+#[lang = "start"]
+fn lang_start<T: ::termination::Termination + 'static>
+    (main: fn() -> T, argc: isize, argv: *const *const u8) -> !
+{
+    lang_start_real(move || main().report(), argc, argv)
+}
+
 #[cfg(all(not(test), stage0))]
 #[lang = "start"]
 fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {