about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorMark Drobnak <mark.drobnak@gmail.com>2022-06-07 19:57:15 -0700
committerMark Drobnak <mark.drobnak@gmail.com>2022-06-13 20:45:26 -0700
commitc814f842e46de25c95e08551a29f06ede1880a47 (patch)
treed7421aa8871511221faa3740403f1b756adfb1c3 /library/std/src
parent5d5039e1b80862b4561a5199d57053f1ef027035 (diff)
downloadrust-c814f842e46de25c95e08551a29f06ede1880a47.tar.gz
rust-c814f842e46de25c95e08551a29f06ede1880a47.zip
Use a private type definition to reduce cfg noise
I checked with t-libs to make sure this is OK to do on stable functions:
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Replacing.20std.20function.20arg.20type.20with.20private.20type.20def.3F
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/os/unix/process.rs52
1 files changed, 16 insertions, 36 deletions
diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs
index 64fd6497463..df33976098f 100644
--- a/library/std/src/os/unix/process.rs
+++ b/library/std/src/os/unix/process.rs
@@ -12,6 +12,16 @@ use crate::sealed::Sealed;
 use crate::sys;
 use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
 
+#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
+type UserId = u32;
+#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
+type GroupId = u32;
+
+#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
+type UserId = u16;
+#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
+type GroupId = u16;
+
 /// Unix-specific extensions to the [`process::Command`] builder.
 ///
 /// This trait is sealed: it cannot be implemented outside the standard library.
@@ -22,32 +32,17 @@ pub trait CommandExt: Sealed {
     /// `setuid` call in the child process. Failure in the `setuid`
     /// call will cause the spawn to fail.
     #[stable(feature = "rust1", since = "1.0.0")]
-    fn uid(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
-        id: u32,
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
-    ) -> &mut process::Command;
+    fn uid(&mut self, id: UserId) -> &mut process::Command;
 
     /// Similar to `uid`, but sets the group ID of the child process. This has
     /// the same semantics as the `uid` field.
     #[stable(feature = "rust1", since = "1.0.0")]
-    fn gid(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
-        id: u32,
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
-    ) -> &mut process::Command;
+    fn gid(&mut self, id: GroupId) -> &mut process::Command;
 
     /// Sets the supplementary group IDs for the calling process. Translates to
     /// a `setgroups` call in the child process.
     #[unstable(feature = "setgroups", issue = "90747")]
-    fn groups(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
-        groups: &[u16],
-    ) -> &mut process::Command;
+    fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command;
 
     /// Schedules a closure to be run just before the `exec` function is
     /// invoked.
@@ -161,32 +156,17 @@ pub trait CommandExt: Sealed {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl CommandExt for process::Command {
-    fn uid(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
-        id: u32,
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
-    ) -> &mut process::Command {
+    fn uid(&mut self, id: UserId) -> &mut process::Command {
         self.as_inner_mut().uid(id);
         self
     }
 
-    fn gid(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
-        id: u32,
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
-    ) -> &mut process::Command {
+    fn gid(&mut self, id: GroupId) -> &mut process::Command {
         self.as_inner_mut().gid(id);
         self
     }
 
-    fn groups(
-        &mut self,
-        #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
-        #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
-        groups: &[u16],
-    ) -> &mut process::Command {
+    fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command {
         self.as_inner_mut().groups(groups);
         self
     }