diff options
| author | Jane Lusby <jlusby@yaah.dev> | 2022-01-28 12:53:36 -0800 |
|---|---|---|
| committer | Jane Lusby <jlusby@yaah.dev> | 2022-01-28 12:53:36 -0800 |
| commit | 91ffbc43b18842594adb997c8eea8c51035bf0e1 (patch) | |
| tree | b6016327779fc749c75f2af275531059a249b220 /library/std | |
| parent | 427eba2f0bacdeaebc992a78eb2889564de7d7cf (diff) | |
| download | rust-91ffbc43b18842594adb997c8eea8c51035bf0e1.tar.gz rust-91ffbc43b18842594adb997c8eea8c51035bf0e1.zip | |
Change Termination::report return type to ExitCode
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/process.rs | 30 | ||||
| -rw-r--r-- | library/std/src/rt.rs | 2 |
2 files changed, 23 insertions, 9 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index e012594dd46..2a66ae03fae 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1676,6 +1676,20 @@ impl ExitCode { pub const FAILURE: ExitCode = ExitCode(imp::ExitCode::FAILURE); } +impl ExitCode { + // This should not be stabilized when stabilizing ExitCode, we don't know that i32 will serve + // all usecases, for example windows seems to use u32, unix uses the 8-15th bits of an i32, we + // likely want to isolate users anything that could restrict the platform specific + // representation of an ExitCode + // + // More info: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426 + #[unstable(feature = "process_exitcode_placeholder", issue = "48711")] + /// Convert an ExitCode into an i32 + pub fn to_i32(self) -> i32 { + self.0.as_i32() + } +} + impl Child { /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] /// error is returned. @@ -2016,20 +2030,20 @@ pub fn id() -> u32 { 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; + fn report(self) -> ExitCode; } #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for () { #[inline] - fn report(self) -> i32 { + fn report(self) -> ExitCode { ExitCode::SUCCESS.report() } } #[unstable(feature = "termination_trait_lib", issue = "43301")] impl<E: fmt::Debug> Termination for Result<(), E> { - fn report(self) -> i32 { + fn report(self) -> ExitCode { match self { Ok(()) => ().report(), Err(err) => Err::<!, _>(err).report(), @@ -2039,14 +2053,14 @@ impl<E: fmt::Debug> Termination for Result<(), E> { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for ! { - fn report(self) -> i32 { + fn report(self) -> ExitCode { self } } #[unstable(feature = "termination_trait_lib", issue = "43301")] impl<E: fmt::Debug> Termination for Result<!, E> { - fn report(self) -> i32 { + fn report(self) -> ExitCode { let Err(err) = self; eprintln!("Error: {:?}", err); ExitCode::FAILURE.report() @@ -2055,7 +2069,7 @@ impl<E: fmt::Debug> Termination for Result<!, E> { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl<E: fmt::Debug> Termination for Result<Infallible, E> { - fn report(self) -> i32 { + fn report(self) -> ExitCode { let Err(err) = self; Err::<!, _>(err).report() } @@ -2064,7 +2078,7 @@ impl<E: fmt::Debug> Termination for Result<Infallible, E> { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for ExitCode { #[inline] - fn report(self) -> i32 { - self.0.as_i32() + fn report(self) -> ExitCode { + self } } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 08e58257572..663537a05fa 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -142,7 +142,7 @@ fn lang_start<T: crate::process::Termination + 'static>( argv: *const *const u8, ) -> isize { let Ok(v) = lang_start_internal( - &move || crate::sys_common::backtrace::__rust_begin_short_backtrace(main).report(), + &move || crate::sys_common::backtrace::__rust_begin_short_backtrace(main).report().to_i32(), argc, argv, ); |
