|
26 | 26 | // Reexport some of our utilities which are expected by other crates. |
27 | 27 | pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; |
28 | 28 |
|
| 29 | +// To reduce the generated code of the new `lang_start`, this function is doing |
| 30 | +// the real work. |
29 | 31 | #[cfg(not(any(test, stage0)))] |
30 | | -#[lang = "start"] |
31 | | -fn lang_start<T: ::termination::Termination + 'static> |
32 | | - (main: fn() -> T, argc: isize, argv: *const *const u8) -> ! |
| 32 | +fn lang_start_real<F>(main: F, argc: isize, argv: *const *const u8) -> ! |
| 33 | + where F: FnOnce() -> i32 + Send + ::panic::UnwindSafe + 'static |
33 | 34 | { |
34 | 35 | use panic; |
35 | 36 | use sys; |
@@ -59,16 +60,24 @@ fn lang_start<T: ::termination::Termination + 'static> |
59 | 60 | // Let's run some code! |
60 | 61 | #[cfg(feature = "backtrace")] |
61 | 62 | let exit_code = panic::catch_unwind(|| { |
62 | | - ::sys_common::backtrace::__rust_begin_short_backtrace(move || main().report()) |
| 63 | + ::sys_common::backtrace::__rust_begin_short_backtrace(move || main()) |
63 | 64 | }); |
64 | 65 | #[cfg(not(feature = "backtrace"))] |
65 | | - let exit_code = panic::catch_unwind(move || main().report()); |
| 66 | + let exit_code = panic::catch_unwind(move || main()); |
66 | 67 |
|
67 | 68 | sys_common::cleanup(); |
68 | 69 | exit_code.unwrap_or(101) |
69 | 70 | }); |
70 | 71 | } |
71 | 72 |
|
| 73 | +#[cfg(not(any(test, stage0)))] |
| 74 | +#[lang = "start"] |
| 75 | +fn lang_start<T: ::termination::Termination + 'static> |
| 76 | + (main: fn() -> T, argc: isize, argv: *const *const u8) -> ! |
| 77 | +{ |
| 78 | + lang_start_real(move || main().report(), argc, argv) |
| 79 | +} |
| 80 | + |
72 | 81 | #[cfg(all(not(test), stage0))] |
73 | 82 | #[lang = "start"] |
74 | 83 | fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize { |
|
0 commit comments