Skip to content

Commit 9c7f6d6

Browse files
committed
Auto merge of #95112 - Dylan-DPC:rollup-0jo0loj, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #93858 (Add a `process_group` method to UNIX `CommandExt`) - #94650 (Relax tests for Windows dos device names) - #94991 (Make Weak::new const) - #95072 (Re-enable parallel debuginfo tests) - #95109 (Extend --check-cfg tests to all predicate inside all/any) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3153584 + 22b4c40 commit 9c7f6d6

File tree

10 files changed

+220
-19
lines changed

10 files changed

+220
-19
lines changed

library/alloc/src/rc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,10 @@ impl<T> Weak<T> {
21122112
/// assert!(empty.upgrade().is_none());
21132113
/// ```
21142114
#[stable(feature = "downgraded_weak", since = "1.10.0")]
2115+
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
21152116
#[must_use]
2116-
pub fn new() -> Weak<T> {
2117-
Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
2117+
pub const fn new() -> Weak<T> {
2118+
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut RcBox<T>) } }
21182119
}
21192120
}
21202121

library/alloc/src/sync.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1742,9 +1742,10 @@ impl<T> Weak<T> {
17421742
/// assert!(empty.upgrade().is_none());
17431743
/// ```
17441744
#[stable(feature = "downgraded_weak", since = "1.10.0")]
1745+
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
17451746
#[must_use]
1746-
pub fn new() -> Weak<T> {
1747-
Weak { ptr: NonNull::new(usize::MAX as *mut ArcInner<T>).expect("MAX is not 0") }
1747+
pub const fn new() -> Weak<T> {
1748+
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut ArcInner<T>) } }
17481749
}
17491750
}
17501751

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

+10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ pub trait CommandExt: Sealed {
149149
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
150150
where
151151
S: AsRef<OsStr>;
152+
153+
/// Sets the process group ID of the child process. Translates to a `setpgid` call in the child
154+
/// process.
155+
#[unstable(feature = "process_set_process_group", issue = "93857")]
156+
fn process_group(&mut self, pgroup: i32) -> &mut process::Command;
152157
}
153158

154159
#[stable(feature = "rust1", since = "1.0.0")]
@@ -201,6 +206,11 @@ impl CommandExt for process::Command {
201206
self.as_inner_mut().set_arg_0(arg.as_ref());
202207
self
203208
}
209+
210+
fn process_group(&mut self, pgroup: i32) -> &mut process::Command {
211+
self.as_inner_mut().pgroup(pgroup);
212+
self
213+
}
204214
}
205215

206216
/// Unix-specific extensions to [`process::ExitStatus`] and

library/std/src/path/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1739,11 +1739,11 @@ fn test_windows_absolute() {
17391739
let relative = r"a\b";
17401740
let mut expected = crate::env::current_dir().unwrap();
17411741
expected.push(relative);
1742-
assert_eq!(absolute(relative).unwrap(), expected);
1742+
assert_eq!(absolute(relative).unwrap().as_os_str(), expected.as_os_str());
17431743

17441744
macro_rules! unchanged(
17451745
($path:expr) => {
1746-
assert_eq!(absolute($path).unwrap(), Path::new($path));
1746+
assert_eq!(absolute($path).unwrap().as_os_str(), Path::new($path).as_os_str());
17471747
}
17481748
);
17491749

@@ -1759,11 +1759,11 @@ fn test_windows_absolute() {
17591759
// Verbatim paths are always unchanged, no matter what.
17601760
unchanged!(r"\\?\path.\to/file..");
17611761

1762-
assert_eq!(absolute(r"C:\path..\to.\file.").unwrap(), Path::new(r"C:\path..\to\file"));
1763-
assert_eq!(absolute(r"C:\path\to\COM1").unwrap(), Path::new(r"\\.\COM1"));
1764-
assert_eq!(absolute(r"C:\path\to\COM1.txt").unwrap(), Path::new(r"\\.\COM1"));
1765-
assert_eq!(absolute(r"C:\path\to\COM1 .txt").unwrap(), Path::new(r"\\.\COM1"));
1766-
assert_eq!(absolute(r"C:\path\to\cOnOuT$").unwrap(), Path::new(r"\\.\cOnOuT$"));
1762+
assert_eq!(
1763+
absolute(r"C:\path..\to.\file.").unwrap().as_os_str(),
1764+
Path::new(r"C:\path..\to\file").as_os_str()
1765+
);
1766+
assert_eq!(absolute(r"COM1").unwrap().as_os_str(), Path::new(r"\\.\COM1").as_os_str());
17671767
}
17681768

17691769
#[bench]

library/std/src/sys/unix/process/process_common.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::sys_common::IntoInner;
1818
#[cfg(not(target_os = "fuchsia"))]
1919
use crate::sys::fs::OpenOptions;
2020

21-
use libc::{c_char, c_int, gid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS};
21+
use libc::{c_char, c_int, gid_t, pid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS};
2222

2323
cfg_if::cfg_if! {
2424
if #[cfg(target_os = "fuchsia")] {
@@ -82,6 +82,7 @@ pub struct Command {
8282
stderr: Option<Stdio>,
8383
#[cfg(target_os = "linux")]
8484
create_pidfd: bool,
85+
pgroup: Option<pid_t>,
8586
}
8687

8788
// Create a new type for argv, so that we can make it `Send` and `Sync`
@@ -145,6 +146,7 @@ impl Command {
145146
stdin: None,
146147
stdout: None,
147148
stderr: None,
149+
pgroup: None,
148150
}
149151
}
150152

@@ -167,6 +169,7 @@ impl Command {
167169
stdout: None,
168170
stderr: None,
169171
create_pidfd: false,
172+
pgroup: None,
170173
}
171174
}
172175

@@ -202,6 +205,9 @@ impl Command {
202205
pub fn groups(&mut self, groups: &[gid_t]) {
203206
self.groups = Some(Box::from(groups));
204207
}
208+
pub fn pgroup(&mut self, pgroup: pid_t) {
209+
self.pgroup = Some(pgroup);
210+
}
205211

206212
#[cfg(target_os = "linux")]
207213
pub fn create_pidfd(&mut self, val: bool) {
@@ -265,6 +271,10 @@ impl Command {
265271
pub fn get_groups(&self) -> Option<&[gid_t]> {
266272
self.groups.as_deref()
267273
}
274+
#[allow(dead_code)]
275+
pub fn get_pgroup(&self) -> Option<pid_t> {
276+
self.pgroup
277+
}
268278

269279
pub fn get_closures(&mut self) -> &mut Vec<Box<dyn FnMut() -> io::Result<()> + Send + Sync>> {
270280
&mut self.closures

library/std/src/sys/unix/process/process_common/tests.rs

+55
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,58 @@ fn test_process_mask() {
6767
t!(cat.wait());
6868
}
6969
}
70+
71+
#[test]
72+
#[cfg_attr(
73+
any(
74+
// See test_process_mask
75+
target_os = "macos",
76+
target_arch = "arm",
77+
target_arch = "aarch64",
78+
target_arch = "riscv64",
79+
),
80+
ignore
81+
)]
82+
fn test_process_group_posix_spawn() {
83+
unsafe {
84+
// Spawn a cat subprocess that's just going to hang since there is no I/O.
85+
let mut cmd = Command::new(OsStr::new("cat"));
86+
cmd.pgroup(0);
87+
cmd.stdin(Stdio::MakePipe);
88+
cmd.stdout(Stdio::MakePipe);
89+
let (mut cat, _pipes) = t!(cmd.spawn(Stdio::Null, true));
90+
91+
// Check that we can kill its process group, which means there *is* one.
92+
t!(cvt(libc::kill(-(cat.id() as libc::pid_t), libc::SIGINT)));
93+
94+
t!(cat.wait());
95+
}
96+
}
97+
98+
#[test]
99+
#[cfg_attr(
100+
any(
101+
// See test_process_mask
102+
target_os = "macos",
103+
target_arch = "arm",
104+
target_arch = "aarch64",
105+
target_arch = "riscv64",
106+
),
107+
ignore
108+
)]
109+
fn test_process_group_no_posix_spawn() {
110+
unsafe {
111+
// Same as above, create hang-y cat. This time, force using the non-posix_spawnp path.
112+
let mut cmd = Command::new(OsStr::new("cat"));
113+
cmd.pgroup(0);
114+
cmd.pre_exec(Box::new(|| Ok(()))); // pre_exec forces fork + exec
115+
cmd.stdin(Stdio::MakePipe);
116+
cmd.stdout(Stdio::MakePipe);
117+
let (mut cat, _pipes) = t!(cmd.spawn(Stdio::Null, true));
118+
119+
// Check that we can kill its process group, which means there *is* one.
120+
t!(cvt(libc::kill(-(cat.id() as libc::pid_t), libc::SIGINT)));
121+
122+
t!(cat.wait());
123+
}
124+
}

library/std/src/sys/unix/process/process_unix.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ impl Command {
320320
cvt(libc::chdir(cwd.as_ptr()))?;
321321
}
322322

323+
if let Some(pgroup) = self.get_pgroup() {
324+
cvt(libc::setpgid(0, pgroup))?;
325+
}
326+
323327
// emscripten has no signal support.
324328
#[cfg(not(target_os = "emscripten"))]
325329
{
@@ -459,6 +463,8 @@ impl Command {
459463
None => None,
460464
};
461465

466+
let pgroup = self.get_pgroup();
467+
462468
// Safety: -1 indicates we don't have a pidfd.
463469
let mut p = unsafe { Process::new(0, -1) };
464470

@@ -487,6 +493,8 @@ impl Command {
487493
cvt_nz(libc::posix_spawnattr_init(attrs.as_mut_ptr()))?;
488494
let attrs = PosixSpawnattr(&mut attrs);
489495

496+
let mut flags = 0;
497+
490498
let mut file_actions = MaybeUninit::uninit();
491499
cvt_nz(libc::posix_spawn_file_actions_init(file_actions.as_mut_ptr()))?;
492500
let file_actions = PosixSpawnFileActions(&mut file_actions);
@@ -516,13 +524,18 @@ impl Command {
516524
cvt_nz(f(file_actions.0.as_mut_ptr(), cwd.as_ptr()))?;
517525
}
518526

527+
if let Some(pgroup) = pgroup {
528+
flags |= libc::POSIX_SPAWN_SETPGROUP;
529+
cvt_nz(libc::posix_spawnattr_setpgroup(attrs.0.as_mut_ptr(), pgroup))?;
530+
}
531+
519532
let mut set = MaybeUninit::<libc::sigset_t>::uninit();
520533
cvt(sigemptyset(set.as_mut_ptr()))?;
521534
cvt_nz(libc::posix_spawnattr_setsigmask(attrs.0.as_mut_ptr(), set.as_ptr()))?;
522535
cvt(sigaddset(set.as_mut_ptr(), libc::SIGPIPE))?;
523536
cvt_nz(libc::posix_spawnattr_setsigdefault(attrs.0.as_mut_ptr(), set.as_ptr()))?;
524537

525-
let flags = libc::POSIX_SPAWN_SETSIGDEF | libc::POSIX_SPAWN_SETSIGMASK;
538+
flags |= libc::POSIX_SPAWN_SETSIGDEF | libc::POSIX_SPAWN_SETSIGMASK;
526539
cvt_nz(libc::posix_spawnattr_setflags(attrs.0.as_mut_ptr(), flags as _))?;
527540

528541
// Make sure we synchronize access to the global `environ` resource

src/test/ui/check-cfg/mix.rs

+22
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ fn test_cfg_macro() {
4545
//~^ WARNING unexpected `cfg` condition name
4646
cfg!(any(feature = "bad", windows));
4747
//~^ WARNING unexpected `cfg` condition value
48+
cfg!(any(windows, xxx));
49+
//~^ WARNING unexpected `cfg` condition name
50+
cfg!(all(unix, xxx));
51+
//~^ WARNING unexpected `cfg` condition name
52+
cfg!(all(aa, bb));
53+
//~^ WARNING unexpected `cfg` condition name
54+
//~| WARNING unexpected `cfg` condition name
55+
cfg!(any(aa, bb));
56+
//~^ WARNING unexpected `cfg` condition name
57+
//~| WARNING unexpected `cfg` condition name
58+
cfg!(any(unix, feature = "zebra"));
59+
//~^ WARNING unexpected `cfg` condition value
60+
cfg!(any(xxx, feature = "zebra"));
61+
//~^ WARNING unexpected `cfg` condition name
62+
//~| WARNING unexpected `cfg` condition value
63+
cfg!(any(xxx, unix, xxx));
64+
//~^ WARNING unexpected `cfg` condition name
65+
//~| WARNING unexpected `cfg` condition name
66+
cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
67+
//~^ WARNING unexpected `cfg` condition value
68+
//~| WARNING unexpected `cfg` condition value
69+
//~| WARNING unexpected `cfg` condition value
4870
}
4971

5072
fn main() {}

src/test/ui/check-cfg/mix.stderr

+95-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,99 @@ LL | cfg!(any(feature = "bad", windows));
6262
|
6363
= note: expected values for `feature` are: bar, foo
6464

65-
warning: 9 warnings emitted
65+
warning: unexpected `cfg` condition name
66+
--> $DIR/mix.rs:48:23
67+
|
68+
LL | cfg!(any(windows, xxx));
69+
| ^^^
70+
71+
warning: unexpected `cfg` condition name
72+
--> $DIR/mix.rs:50:20
73+
|
74+
LL | cfg!(all(unix, xxx));
75+
| ^^^
76+
77+
warning: unexpected `cfg` condition name
78+
--> $DIR/mix.rs:52:14
79+
|
80+
LL | cfg!(all(aa, bb));
81+
| ^^
82+
83+
warning: unexpected `cfg` condition name
84+
--> $DIR/mix.rs:52:18
85+
|
86+
LL | cfg!(all(aa, bb));
87+
| ^^
88+
89+
warning: unexpected `cfg` condition name
90+
--> $DIR/mix.rs:55:14
91+
|
92+
LL | cfg!(any(aa, bb));
93+
| ^^
94+
95+
warning: unexpected `cfg` condition name
96+
--> $DIR/mix.rs:55:18
97+
|
98+
LL | cfg!(any(aa, bb));
99+
| ^^
100+
101+
warning: unexpected `cfg` condition value
102+
--> $DIR/mix.rs:58:20
103+
|
104+
LL | cfg!(any(unix, feature = "zebra"));
105+
| ^^^^^^^^^^^^^^^^^
106+
|
107+
= note: expected values for `feature` are: bar, foo
108+
109+
warning: unexpected `cfg` condition name
110+
--> $DIR/mix.rs:60:14
111+
|
112+
LL | cfg!(any(xxx, feature = "zebra"));
113+
| ^^^
114+
115+
warning: unexpected `cfg` condition value
116+
--> $DIR/mix.rs:60:19
117+
|
118+
LL | cfg!(any(xxx, feature = "zebra"));
119+
| ^^^^^^^^^^^^^^^^^
120+
|
121+
= note: expected values for `feature` are: bar, foo
122+
123+
warning: unexpected `cfg` condition name
124+
--> $DIR/mix.rs:63:14
125+
|
126+
LL | cfg!(any(xxx, unix, xxx));
127+
| ^^^
128+
129+
warning: unexpected `cfg` condition name
130+
--> $DIR/mix.rs:63:25
131+
|
132+
LL | cfg!(any(xxx, unix, xxx));
133+
| ^^^
134+
135+
warning: unexpected `cfg` condition value
136+
--> $DIR/mix.rs:66:14
137+
|
138+
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
139+
| ^^^^^^^^^^^^^^^^^
140+
|
141+
= note: expected values for `feature` are: bar, foo
142+
143+
warning: unexpected `cfg` condition value
144+
--> $DIR/mix.rs:66:33
145+
|
146+
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
147+
| ^^^^^^^^^^^^^^^^^
148+
|
149+
= note: expected values for `feature` are: bar, foo
150+
151+
warning: unexpected `cfg` condition value
152+
--> $DIR/mix.rs:66:52
153+
|
154+
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
155+
| ^^^^^^^^^^^^^^^^^
156+
|
157+
= note: expected values for `feature` are: bar, foo
158+
159+
warning: 23 warnings emitted
66160

src/tools/compiletest/src/main.rs

-5
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,6 @@ fn configure_lldb(config: &Config) -> Option<Config> {
487487
return None;
488488
}
489489

490-
// Some older versions of LLDB seem to have problems with multiple
491-
// instances running in parallel, so only run one test thread at a
492-
// time.
493-
env::set_var("RUST_TEST_THREADS", "1");
494-
495490
Some(Config { debugger: Some(Debugger::Lldb), ..config.clone() })
496491
}
497492

0 commit comments

Comments
 (0)