Skip to content

Commit c814f84

Browse files
committed
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
1 parent 5d5039e commit c814f84

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

library/std/src/os/unix/process.rs

+16-36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ use crate::sealed::Sealed;
1212
use crate::sys;
1313
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1414

15+
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
16+
type UserId = u32;
17+
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
18+
type GroupId = u32;
19+
20+
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
21+
type UserId = u16;
22+
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
23+
type GroupId = u16;
24+
1525
/// Unix-specific extensions to the [`process::Command`] builder.
1626
///
1727
/// This trait is sealed: it cannot be implemented outside the standard library.
@@ -22,32 +32,17 @@ pub trait CommandExt: Sealed {
2232
/// `setuid` call in the child process. Failure in the `setuid`
2333
/// call will cause the spawn to fail.
2434
#[stable(feature = "rust1", since = "1.0.0")]
25-
fn uid(
26-
&mut self,
27-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
28-
id: u32,
29-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
30-
) -> &mut process::Command;
35+
fn uid(&mut self, id: UserId) -> &mut process::Command;
3136

3237
/// Similar to `uid`, but sets the group ID of the child process. This has
3338
/// the same semantics as the `uid` field.
3439
#[stable(feature = "rust1", since = "1.0.0")]
35-
fn gid(
36-
&mut self,
37-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
38-
id: u32,
39-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
40-
) -> &mut process::Command;
40+
fn gid(&mut self, id: GroupId) -> &mut process::Command;
4141

4242
/// Sets the supplementary group IDs for the calling process. Translates to
4343
/// a `setgroups` call in the child process.
4444
#[unstable(feature = "setgroups", issue = "90747")]
45-
fn groups(
46-
&mut self,
47-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
48-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
49-
groups: &[u16],
50-
) -> &mut process::Command;
45+
fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command;
5146

5247
/// Schedules a closure to be run just before the `exec` function is
5348
/// invoked.
@@ -161,32 +156,17 @@ pub trait CommandExt: Sealed {
161156

162157
#[stable(feature = "rust1", since = "1.0.0")]
163158
impl CommandExt for process::Command {
164-
fn uid(
165-
&mut self,
166-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
167-
id: u32,
168-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
169-
) -> &mut process::Command {
159+
fn uid(&mut self, id: UserId) -> &mut process::Command {
170160
self.as_inner_mut().uid(id);
171161
self
172162
}
173163

174-
fn gid(
175-
&mut self,
176-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
177-
id: u32,
178-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
179-
) -> &mut process::Command {
164+
fn gid(&mut self, id: GroupId) -> &mut process::Command {
180165
self.as_inner_mut().gid(id);
181166
self
182167
}
183168

184-
fn groups(
185-
&mut self,
186-
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
187-
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
188-
groups: &[u16],
189-
) -> &mut process::Command {
169+
fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command {
190170
self.as_inner_mut().groups(groups);
191171
self
192172
}

0 commit comments

Comments
 (0)