Skip to content

Commit 788202a

Browse files
committed
Auto merge of rust-lang#132121 - workingjubilee:rollup-yrtn33e, r=workingjubilee
Rollup of 6 pull requests Successful merges: - rust-lang#131851 ([musl] use posix_spawn if a directory change was requested) - rust-lang#132048 (AIX: use /dev/urandom for random implementation ) - rust-lang#132093 (compiletest: suppress Windows Error Reporting (WER) for `run-make` tests) - rust-lang#132101 (Avoid using imports in thread_local_inner! in static) - rust-lang#132113 (Provide a default impl for Pattern::as_utf8_pattern) - rust-lang#132115 (rustdoc: Extend fake_variadic to "wrapped" tuples) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3dc1b9f + 3549dbb commit 788202a

File tree

11 files changed

+138
-43
lines changed

11 files changed

+138
-43
lines changed

compiler/rustc_passes/src/check_attr.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
918918
};
919919
match item_kind {
920920
Some(ItemKind::Impl(i)) => {
921-
let is_valid = matches!(&i.self_ty.kind, hir::TyKind::Tup([_]))
922-
|| if let hir::TyKind::BareFn(bare_fn_ty) = &i.self_ty.kind {
923-
bare_fn_ty.decl.inputs.len() == 1
924-
} else {
925-
false
926-
}
921+
let is_valid = doc_fake_variadic_is_allowed_self_ty(i.self_ty)
927922
|| if let Some(&[hir::GenericArg::Type(ty)]) = i
928923
.of_trait
929924
.as_ref()
@@ -2630,3 +2625,20 @@ fn check_duplicates(
26302625
},
26312626
}
26322627
}
2628+
2629+
fn doc_fake_variadic_is_allowed_self_ty(self_ty: &hir::Ty<'_>) -> bool {
2630+
matches!(&self_ty.kind, hir::TyKind::Tup([_]))
2631+
|| if let hir::TyKind::BareFn(bare_fn_ty) = &self_ty.kind {
2632+
bare_fn_ty.decl.inputs.len() == 1
2633+
} else {
2634+
false
2635+
}
2636+
|| (if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &self_ty.kind
2637+
&& let Some(&[hir::GenericArg::Type(ty)]) =
2638+
path.segments.last().map(|last| last.args().args)
2639+
{
2640+
doc_fake_variadic_is_allowed_self_ty(ty)
2641+
} else {
2642+
false
2643+
})
2644+
}

library/core/src/str/pattern.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ pub trait Pattern: Sized {
162162
}
163163

164164
/// Returns the pattern as utf-8 bytes if possible.
165-
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>;
165+
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
166+
None
167+
}
166168
}
167169
/// Result of calling [`Pattern::as_utf8_pattern()`].
168170
/// Can be used for inspecting the contents of a [`Pattern`] in cases
@@ -675,11 +677,6 @@ impl<C: MultiCharEq> Pattern for MultiCharEqPattern<C> {
675677
fn into_searcher(self, haystack: &str) -> MultiCharEqSearcher<'_, C> {
676678
MultiCharEqSearcher { haystack, char_eq: self.0, char_indices: haystack.char_indices() }
677679
}
678-
679-
#[inline]
680-
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
681-
None
682-
}
683680
}
684681

685682
unsafe impl<'a, C: MultiCharEq> Searcher<'a> for MultiCharEqSearcher<'a, C> {
@@ -770,11 +767,6 @@ macro_rules! pattern_methods {
770767
{
771768
($pmap)(self).strip_suffix_of(haystack)
772769
}
773-
774-
#[inline]
775-
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
776-
None
777-
}
778770
};
779771
}
780772

library/std/src/process/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,23 @@ fn stdout_works() {
9696
#[test]
9797
#[cfg_attr(any(windows, target_os = "vxworks"), ignore)]
9898
fn set_current_dir_works() {
99+
// On many Unix platforms this will use the posix_spawn path.
99100
let mut cmd = shell_cmd();
100101
cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
101102
assert_eq!(run_output(cmd), "/\n");
103+
104+
// Also test the fork/exec path by setting a pre_exec function.
105+
#[cfg(unix)]
106+
{
107+
use crate::os::unix::process::CommandExt;
108+
109+
let mut cmd = shell_cmd();
110+
cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
111+
unsafe {
112+
cmd.pre_exec(|| Ok(()));
113+
}
114+
assert_eq!(run_output(cmd), "/\n");
115+
}
102116
}
103117

104118
#[test]

library/std/src/random.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::sys::random as sys;
3838
/// Vita | `arc4random_buf`
3939
/// Hermit | `read_entropy`
4040
/// Horizon | `getrandom` shim
41-
/// Hurd, L4Re, QNX | `/dev/urandom`
41+
/// AIX, Hurd, L4Re, QNX | `/dev/urandom`
4242
/// Redox | `/scheme/rand`
4343
/// RTEMS | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)
4444
/// SGX | [`rdrand`](https://en.wikipedia.org/wiki/RDRAND)

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

+43-11
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ impl Command {
448448
use core::sync::atomic::{AtomicU8, Ordering};
449449

450450
use crate::mem::MaybeUninit;
451-
use crate::sys::weak::weak;
452451
use crate::sys::{self, cvt_nz, on_broken_pipe_flag_used};
453452

454453
if self.get_gid().is_some()
@@ -462,6 +461,8 @@ impl Command {
462461

463462
cfg_if::cfg_if! {
464463
if #[cfg(target_os = "linux")] {
464+
use crate::sys::weak::weak;
465+
465466
weak! {
466467
fn pidfd_spawnp(
467468
*mut libc::c_int,
@@ -575,16 +576,44 @@ impl Command {
575576
}
576577
}
577578

578-
// Solaris, glibc 2.29+, and musl 1.24+ can set a new working directory,
579-
// and maybe others will gain this non-POSIX function too. We'll check
580-
// for this weak symbol as soon as it's needed, so we can return early
581-
// otherwise to do a manual chdir before exec.
582-
weak! {
583-
fn posix_spawn_file_actions_addchdir_np(
584-
*mut libc::posix_spawn_file_actions_t,
585-
*const libc::c_char
586-
) -> libc::c_int
579+
type PosixSpawnAddChdirFn = unsafe extern "C" fn(
580+
*mut libc::posix_spawn_file_actions_t,
581+
*const libc::c_char,
582+
) -> libc::c_int;
583+
584+
/// Get the function pointer for adding a chdir action to a
585+
/// `posix_spawn_file_actions_t`, if available, assuming a dynamic libc.
586+
///
587+
/// Some platforms can set a new working directory for a spawned process in the
588+
/// `posix_spawn` path. This function looks up the function pointer for adding
589+
/// such an action to a `posix_spawn_file_actions_t` struct.
590+
#[cfg(not(all(target_os = "linux", target_env = "musl")))]
591+
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
592+
use crate::sys::weak::weak;
593+
594+
weak! {
595+
fn posix_spawn_file_actions_addchdir_np(
596+
*mut libc::posix_spawn_file_actions_t,
597+
*const libc::c_char
598+
) -> libc::c_int
599+
}
600+
601+
posix_spawn_file_actions_addchdir_np.get()
602+
}
603+
604+
/// Get the function pointer for adding a chdir action to a
605+
/// `posix_spawn_file_actions_t`, if available, on platforms where the function
606+
/// is known to exist.
607+
///
608+
/// Weak symbol lookup doesn't work with statically linked libcs, so in cases
609+
/// where static linking is possible we need to either check for the presence
610+
/// of the symbol at compile time or know about it upfront.
611+
#[cfg(all(target_os = "linux", target_env = "musl"))]
612+
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
613+
// Our minimum required musl supports this function, so we can just use it.
614+
Some(libc::posix_spawn_file_actions_addchdir_np)
587615
}
616+
588617
let addchdir = match self.get_cwd() {
589618
Some(cwd) => {
590619
if cfg!(target_vendor = "apple") {
@@ -597,7 +626,10 @@ impl Command {
597626
return Ok(None);
598627
}
599628
}
600-
match posix_spawn_file_actions_addchdir_np.get() {
629+
// Check for the availability of the posix_spawn addchdir
630+
// function now. If it isn't available, bail and use the
631+
// fork/exec path.
632+
match get_posix_spawn_addchdir() {
601633
Some(f) => Some((f, cwd)),
602634
None => return Ok(None),
603635
}

library/std/src/sys/random/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cfg_if::cfg_if! {
4040
mod horizon;
4141
pub use horizon::fill_bytes;
4242
} else if #[cfg(any(
43+
target_os = "aix",
4344
target_os = "hurd",
4445
target_os = "l4re",
4546
target_os = "nto",

library/std/src/sys/thread_local/statik.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ pub macro thread_local_inner {
1414
(@key $t:ty, const $init:expr) => {{
1515
const __INIT: $t = $init;
1616

17+
// NOTE: Please update the shadowing test in `tests/thread.rs` if these types are renamed.
1718
unsafe {
18-
use $crate::thread::LocalKey;
19-
use $crate::thread::local_impl::EagerStorage;
20-
21-
LocalKey::new(|_| {
22-
static VAL: EagerStorage<$t> = EagerStorage { value: __INIT };
19+
$crate::thread::LocalKey::new(|_| {
20+
static VAL: $crate::thread::local_impl::EagerStorage<$t> =
21+
$crate::thread::local_impl::EagerStorage { value: __INIT };
2322
&VAL.value
2423
})
2524
}

src/librustdoc/html/format.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,24 @@ impl clean::Impl {
13681368
write!(f, " -> ")?;
13691369
fmt_type(&bare_fn.decl.output, f, use_absolute, cx)?;
13701370
}
1371+
} else if let clean::Type::Path { path } = type_
1372+
&& let Some(generics) = path.generics()
1373+
&& generics.len() == 1
1374+
&& self.kind.is_fake_variadic()
1375+
{
1376+
let ty = generics[0];
1377+
let wrapper = anchor(path.def_id(), path.last(), cx);
1378+
if f.alternate() {
1379+
write!(f, "{wrapper:#}&lt;")?;
1380+
} else {
1381+
write!(f, "{wrapper}<")?;
1382+
}
1383+
self.print_type(ty, f, use_absolute, cx)?;
1384+
if f.alternate() {
1385+
write!(f, "&gt;")?;
1386+
} else {
1387+
write!(f, ">")?;
1388+
}
13711389
} else {
13721390
fmt_type(&type_, f, use_absolute, cx)?;
13731391
}

src/tools/compiletest/src/runtest.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,29 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
5959
use std::sync::Mutex;
6060

6161
use windows::Win32::System::Diagnostics::Debug::{
62-
SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
62+
SEM_FAILCRITICALERRORS, SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
6363
};
6464

6565
static LOCK: Mutex<()> = Mutex::new(());
6666

6767
// Error mode is a global variable, so lock it so only one thread will change it
6868
let _lock = LOCK.lock().unwrap();
6969

70-
// Tell Windows to not show any UI on errors (such as terminating abnormally).
71-
// This is important for running tests, since some of them use abnormal
72-
// termination by design. This mode is inherited by all child processes.
70+
// Tell Windows to not show any UI on errors (such as terminating abnormally). This is important
71+
// for running tests, since some of them use abnormal termination by design. This mode is
72+
// inherited by all child processes.
73+
//
74+
// Note that `run-make` tests require `SEM_FAILCRITICALERRORS` in addition to suppress Windows
75+
// Error Reporting (WER) error dialogues that come from "critical failures" such as missing
76+
// DLLs.
77+
//
78+
// See <https://github.com/rust-lang/rust/issues/132092> and
79+
// <https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode?redirectedfrom=MSDN>.
7380
unsafe {
74-
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
81+
// read inherited flags
82+
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
7583
let old_mode = THREAD_ERROR_MODE(old_mode);
76-
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX);
84+
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
7785
let r = f();
7886
SetErrorMode(old_mode);
7987
r

src/tools/compiletest/src/runtest/run_make.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::Path;
22
use std::process::{Command, Output, Stdio};
33
use std::{env, fs};
44

5-
use super::{ProcRes, TestCx};
5+
use super::{ProcRes, TestCx, disable_error_reporting};
66
use crate::util::{copy_dir_all, dylib_env_var};
77

88
impl TestCx<'_> {
@@ -514,8 +514,8 @@ impl TestCx<'_> {
514514
}
515515
}
516516

517-
let (Output { stdout, stderr, status }, truncated) =
518-
self.read2_abbreviated(cmd.spawn().expect("failed to spawn `rmake`"));
517+
let proc = disable_error_reporting(|| cmd.spawn().expect("failed to spawn `rmake`"));
518+
let (Output { stdout, stderr, status }, truncated) = self.read2_abbreviated(proc);
519519
if !status.success() {
520520
let res = ProcRes {
521521
status,

tests/rustdoc/primitive-tuple-variadic.rs

+19
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,22 @@ impl<T> Baz<[T; 1]> for (T,) {}
3333
//@ has - '//section[@id="impl-Baz%3CT%3E-for-(T,)"]/h3' 'impl<T> Baz<T> for (T₁, T₂, …, Tₙ)'
3434
#[doc(fake_variadic)]
3535
impl<T> Baz<T> for (T,) {}
36+
37+
pub trait Qux {}
38+
39+
pub struct NewType<T>(T);
40+
41+
//@ has foo/trait.Qux.html
42+
//@ has - '//section[@id="impl-Qux-for-NewType%3C(T,)%3E"]/h3' 'impl<T> Qux for NewType<(T₁, T₂, …, Tₙ)>'
43+
#[doc(fake_variadic)]
44+
impl<T> Qux for NewType<(T,)> {}
45+
46+
//@ has foo/trait.Qux.html
47+
//@ has - '//section[@id="impl-Qux-for-NewType%3CNewType%3C(T,)%3E%3E"]/h3' 'impl<T> Qux for NewType<NewType<(T₁, T₂, …, Tₙ)>>'
48+
#[doc(fake_variadic)]
49+
impl<T> Qux for NewType<NewType<(T,)>> {}
50+
51+
//@ has foo/trait.Qux.html
52+
//@ has - '//section[@id="impl-Qux-for-NewType%3Cfn(T)+-%3E+Out%3E"]/h3' 'impl<T, Out> Qux for NewType<fn(T₁, T₂, …, Tₙ) -> Out>'
53+
#[doc(fake_variadic)]
54+
impl<T, Out> Qux for NewType<fn(T) -> Out> {}

0 commit comments

Comments
 (0)