about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-14 18:46:19 +0000
committerbors <bors@rust-lang.org>2023-10-14 18:46:19 +0000
commitee8c9d3c34719a129f280cd91ba5d324017bb02b (patch)
treee1ab870ec5d3cf3b4bc8e3875daf98c62c02c6fb /library/std/src
parent8de6f99e32d576d1a0969b75e9b206a4a55c9f7b (diff)
parent77b578f72bbab10cc74581a6ef718b5395c4f2e5 (diff)
downloadrust-ee8c9d3c34719a129f280cd91ba5d324017bb02b.tar.gz
rust-ee8c9d3c34719a129f280cd91ba5d324017bb02b.zip
Auto merge of #116737 - matthiaskrgr:rollup-jftlnmt, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #115439 (rustdoc: hide `#[repr(transparent)]` if it isn't part of the public ABI)
 - #116591 (Don't accidentally detect the commit hash as an `fadd` instruction)
 - #116603 (Reorganize `bootstrap/Cargo.toml`)
 - #116715 (Prevent more spurious unreachable pattern lints)
 - #116723 (Fix broken build on ESP-IDF caused by #115108)
 - #116730 (Add some unsoundness tests for opaques capturing hidden regions not in substs)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/process/mod.rs8
-rw-r--r--library/std/src/sys/unix/process/process_unsupported.rs4
-rw-r--r--library/std/src/sys/unix/process/process_unsupported/wait_status.rs16
3 files changed, 24 insertions, 4 deletions
diff --git a/library/std/src/sys/unix/process/mod.rs b/library/std/src/sys/unix/process/mod.rs
index 0cf163d9fb8..947ef4c8aef 100644
--- a/library/std/src/sys/unix/process/mod.rs
+++ b/library/std/src/sys/unix/process/mod.rs
@@ -6,6 +6,9 @@ pub use crate::sys_common::process::CommandEnvs;
 #[cfg_attr(any(target_os = "espidf", target_os = "horizon"), allow(unused))]
 mod process_common;
 
+#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
+mod process_unsupported;
+
 cfg_if::cfg_if! {
     if #[cfg(target_os = "fuchsia")] {
         #[path = "process_fuchsia.rs"]
@@ -15,8 +18,9 @@ cfg_if::cfg_if! {
         #[path = "process_vxworks.rs"]
         mod process_inner;
     } else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
-        #[path = "process_unsupported.rs"]
-        mod process_inner;
+        mod process_inner {
+            pub use super::process_unsupported::*;
+        }
     } else {
         #[path = "process_unix.rs"]
         mod process_inner;
diff --git a/library/std/src/sys/unix/process/process_unsupported.rs b/library/std/src/sys/unix/process/process_unsupported.rs
index 325d3f23be7..2fbb3192265 100644
--- a/library/std/src/sys/unix/process/process_unsupported.rs
+++ b/library/std/src/sys/unix/process/process_unsupported.rs
@@ -63,12 +63,12 @@ pub struct ExitStatusError(NonZero_c_int);
 
 impl Into<ExitStatus> for ExitStatusError {
     fn into(self) -> ExitStatus {
-        ExitStatus(self.0.into())
+        ExitStatus::from(c_int::from(self.0))
     }
 }
 
 impl ExitStatusError {
     pub fn code(self) -> Option<NonZeroI32> {
-        ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
+        ExitStatus::from(c_int::from(self.0)).code().map(|st| st.try_into().unwrap())
     }
 }
diff --git a/library/std/src/sys/unix/process/process_unsupported/wait_status.rs b/library/std/src/sys/unix/process/process_unsupported/wait_status.rs
index 3c649db1a35..72b7ae18cff 100644
--- a/library/std/src/sys/unix/process/process_unsupported/wait_status.rs
+++ b/library/std/src/sys/unix/process/process_unsupported/wait_status.rs
@@ -1,10 +1,13 @@
 //! Emulated wait status for non-Unix #[cfg(unix) platforms
 //!
 //! Separate module to facilitate testing against a real Unix implementation.
+use core::ffi::NonZero_c_int;
 
 use crate::ffi::c_int;
 use crate::fmt;
 
+use super::ExitStatusError;
+
 /// Emulated wait status for use by `process_unsupported.rs`
 ///
 /// Uses the "traditional unix" encoding.  For use on platfors which are `#[cfg(unix)]`
@@ -40,6 +43,19 @@ impl ExitStatus {
         if (w & 0x7f) == 0 { Some((w & 0xff00) >> 8) } else { None }
     }
 
+    #[allow(unused)]
+    pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
+        // This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0. This is
+        // true on all actual versions of Unix, is widely assumed, and is specified in SuS
+        // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
+        // true for a platform pretending to be Unix, the tests (our doctests, and also
+        // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
+        match NonZero_c_int::try_from(self.wait_status) {
+            /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
+            /* was zero, couldn't convert */ Err(_) => Ok(()),
+        }
+    }
+
     pub fn signal(&self) -> Option<i32> {
         let signal = self.wait_status & 0x007f;
         if signal > 0 && signal < 0x7f { Some(signal) } else { None }