diff options
| author | Bastian Köcher <git@kchr.de> | 2017-12-24 00:15:38 +0100 |
|---|---|---|
| committer | Bastian Köcher <git@kchr.de> | 2017-12-26 12:26:39 +0100 |
| commit | 7dfec34a20af59e50f59f73799f471795a50eeb8 (patch) | |
| tree | a0f595b8be8c28de02b030ee3a9a46ef0fb7fee5 /src/libstd | |
| parent | c2f22f01a9263870d33a26e988bb13b8f622ce7a (diff) | |
| download | rust-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.rs | 19 |
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 { |
