Skip to content

Commit dbbba55

Browse files
committed
Rework the exit failure and success declaration for wasm32
1 parent f972f52 commit dbbba55

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/libstd/termination.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@
99
// except according to those terms.
1010

1111
use error::Error;
12-
use libc;
12+
#[cfg(target_arch = "wasm32")]
13+
mod exit {
14+
pub const SUCCESS: i32 = 0;
15+
pub const FAILURE: i32 = 1;
16+
}
17+
#[cfg(not(target_arch = "wasm32"))]
18+
mod exit {
19+
use libc;
20+
pub const SUCCESS: i32 = libc::EXIT_SUCCESS;
21+
pub const FAILURE: i32 = libc::EXIT_FAILURE;
22+
}
1323

1424
/// A trait for implementing arbitrary return types in the `main` function.
1525
///
@@ -31,7 +41,7 @@ pub trait Termination {
3141

3242
#[unstable(feature = "termination_trait", issue = "43301")]
3343
impl Termination for () {
34-
fn report(self) -> i32 { libc::EXIT_SUCCESS }
44+
fn report(self) -> i32 { exit::SUCCESS }
3545
}
3646

3747
#[unstable(feature = "termination_trait", issue = "43301")]
@@ -41,7 +51,7 @@ impl<T: Termination, E: Error> Termination for Result<T, E> {
4151
Ok(val) => val.report(),
4252
Err(err) => {
4353
print_error(err);
44-
libc::EXIT_FAILURE
54+
exit::FAILURE
4555
}
4656
}
4757
}
@@ -64,7 +74,7 @@ impl Termination for ! {
6474
#[unstable(feature = "termination_trait", issue = "43301")]
6575
impl Termination for bool {
6676
fn report(self) -> i32 {
67-
if self { libc::EXIT_SUCCESS } else { libc::EXIT_FAILURE }
77+
if self { exit::SUCCESS } else { exit::FAILURE }
6878
}
6979
}
7080

0 commit comments

Comments
 (0)