Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31ded84

Browse files
committedMar 29, 2025·
Auto merge of rust-lang#139094 - jhpratt:rollup-usgpag3, r=jhpratt
Rollup of 8 pull requests Successful merges: - rust-lang#138692 (Reject `{true,false}` as revision names) - rust-lang#138757 (wasm: increase default thread stack size to 1 MB) - rust-lang#138832 (Start using `with_native_path` in `std::sys::fs`) - rust-lang#138988 (Change the syntax of the internal `weak!` macro) - rust-lang#139044 (bootstrap: Avoid cloning `change-id` list) - rust-lang#139056 (use `try_fold` instead of `fold`) - rust-lang#139057 (use `slice::contains` where applicable) - rust-lang#139086 (Various cleanup in ExprUseVisitor) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2848101 + 3b74a3e commit 31ded84

File tree

30 files changed

+450
-337
lines changed

30 files changed

+450
-337
lines changed
 

‎compiler/rustc_builtin_macros/src/edition_panic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ pub(crate) fn use_panic_2021(mut span: Span) -> bool {
7474
// (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
7575
loop {
7676
let expn = span.ctxt().outer_expn_data();
77-
if let Some(features) = expn.allow_internal_unstable {
78-
if features.iter().any(|&f| f == sym::edition_panic) {
79-
span = expn.call_site;
80-
continue;
81-
}
77+
if let Some(features) = expn.allow_internal_unstable
78+
&& features.contains(&sym::edition_panic)
79+
{
80+
span = expn.call_site;
81+
continue;
8282
}
8383
break expn.edition >= Edition::Edition2021;
8484
}

‎compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
21862186
// indirectly from ThinLTO. In theory these are not needed as ThinLTO could resolve
21872187
// these, but it currently does not do so.
21882188
let can_have_static_objects =
2189-
tcx.sess.lto() == Lto::Thin || tcx.crate_types().iter().any(|ct| *ct == CrateType::Rlib);
2189+
tcx.sess.lto() == Lto::Thin || tcx.crate_types().contains(&CrateType::Rlib);
21902190

21912191
tcx.sess.target.is_like_windows &&
21922192
can_have_static_objects &&

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
604604
if let Some((name, _)) = lang_items::extract(attrs)
605605
&& let Some(lang_item) = LangItem::from_name(name)
606606
{
607-
if WEAK_LANG_ITEMS.iter().any(|&l| l == lang_item) {
607+
if WEAK_LANG_ITEMS.contains(&lang_item) {
608608
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
609609
}
610610
if let Some(link_name) = lang_item.link_name() {

‎compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 49 additions & 93 deletions
Large diffs are not rendered by default.

‎compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
//! from there).
1919
//!
2020
//! The fact that we are inferring borrow kinds as we go results in a
21-
//! semi-hacky interaction with mem-categorization. In particular,
22-
//! mem-categorization will query the current borrow kind as it
23-
//! categorizes, and we'll return the *current* value, but this may get
21+
//! semi-hacky interaction with the way `ExprUseVisitor` is computing
22+
//! `Place`s. In particular, it will query the current borrow kind as it
23+
//! goes, and we'll return the *current* value, but this may get
2424
//! adjusted later. Therefore, in this module, we generally ignore the
25-
//! borrow kind (and derived mutabilities) that are returned from
26-
//! mem-categorization, since they may be inaccurate. (Another option
25+
//! borrow kind (and derived mutabilities) that `ExprUseVisitor` returns
26+
//! within `Place`s, since they may be inaccurate. (Another option
2727
//! would be to use a unification scheme, where instead of returning a
2828
//! concrete borrow kind like `ty::ImmBorrow`, we return a
2929
//! `ty::InferBorrow(upvar_id)` or something like that, but this would

‎compiler/rustc_middle/src/hir/place.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ pub struct Projection<'tcx> {
5353
pub kind: ProjectionKind,
5454
}
5555

56-
/// A `Place` represents how a value is located in memory.
56+
/// A `Place` represents how a value is located in memory. This does not
57+
/// always correspond to a syntactic place expression. For example, when
58+
/// processing a pattern, a `Place` can be used to refer to the sub-value
59+
/// currently being inspected.
5760
///
5861
/// This is an HIR version of [`rustc_middle::mir::Place`].
5962
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
@@ -67,7 +70,10 @@ pub struct Place<'tcx> {
6770
pub projections: Vec<Projection<'tcx>>,
6871
}
6972

70-
/// A `PlaceWithHirId` represents how a value is located in memory.
73+
/// A `PlaceWithHirId` represents how a value is located in memory. This does not
74+
/// always correspond to a syntactic place expression. For example, when
75+
/// processing a pattern, a `Place` can be used to refer to the sub-value
76+
/// currently being inspected.
7177
///
7278
/// This is an HIR version of [`rustc_middle::mir::Place`].
7379
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]

‎compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ fn build_scope_drops<'tcx>(
14961496
// path, then don't generate the drop. (We only take this into
14971497
// account for non-unwind paths so as not to disturb the
14981498
// caching mechanism.)
1499-
if scope.moved_locals.iter().any(|&o| o == local) {
1499+
if scope.moved_locals.contains(&local) {
15001500
continue;
15011501
}
15021502

‎compiler/rustc_passes/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct EntryContext<'tcx> {
2424
}
2525

2626
fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
27-
let any_exe = tcx.crate_types().iter().any(|ty| *ty == CrateType::Executable);
27+
let any_exe = tcx.crate_types().contains(&CrateType::Executable);
2828
if !any_exe {
2929
// No need to find a main function.
3030
return None;

‎compiler/rustc_session/src/utils.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ pub fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
149149
arg[a.len()..].to_string()
150150
};
151151
let option = content.split_once('=').map(|s| s.0).unwrap_or(&content);
152-
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.iter().any(|exc| option == *exc) {
152+
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.contains(&option) {
153153
excluded_cargo_defaults = true;
154154
} else {
155155
result.push(a.to_string());
156-
match ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.iter().find(|s| option == **s) {
157-
Some(s) => result.push(format!("{s}=[REDACTED]")),
158-
None => result.push(content),
159-
}
156+
result.push(if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&option) {
157+
format!("{option}=[REDACTED]")
158+
} else {
159+
content
160+
});
160161
}
161162
}
162163
}

‎compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl Span {
876876
self.ctxt()
877877
.outer_expn_data()
878878
.allow_internal_unstable
879-
.is_some_and(|features| features.iter().any(|&f| f == feature))
879+
.is_some_and(|features| features.contains(&feature))
880880
}
881881

882882
/// Checks if this span arises from a compiler desugaring of kind `kind`.

‎compiler/stable_mir/src/mir/body.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,7 @@ impl Place {
10571057
/// In order to retrieve the correct type, the `locals` argument must match the list of all
10581058
/// locals from the function body where this place originates from.
10591059
pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error> {
1060-
let start_ty = locals[self.local].ty;
1061-
self.projection.iter().fold(Ok(start_ty), |place_ty, elem| elem.ty(place_ty?))
1060+
self.projection.iter().try_fold(locals[self.local].ty, |place_ty, elem| elem.ty(place_ty))
10621061
}
10631062
}
10641063

‎compiler/stable_mir/src/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ pub struct PlaceRef<'a> {
563563
impl PlaceRef<'_> {
564564
/// Get the type of this place.
565565
pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error> {
566-
self.projection.iter().fold(Ok(locals[self.local].ty), |place_ty, elem| elem.ty(place_ty?))
566+
self.projection.iter().try_fold(locals[self.local].ty, |place_ty, elem| elem.ty(place_ty))
567567
}
568568
}
569569

‎library/std/src/fs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ impl AsInner<fs_imp::DirEntry> for DirEntry {
23702370
#[doc(alias = "rm", alias = "unlink", alias = "DeleteFile")]
23712371
#[stable(feature = "rust1", since = "1.0.0")]
23722372
pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
2373-
fs_imp::unlink(path.as_ref())
2373+
fs_imp::remove_file(path.as_ref())
23742374
}
23752375

23762376
/// Given a path, queries the file system to get information about a file,
@@ -2409,7 +2409,7 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
24092409
#[doc(alias = "stat")]
24102410
#[stable(feature = "rust1", since = "1.0.0")]
24112411
pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
2412-
fs_imp::stat(path.as_ref()).map(Metadata)
2412+
fs_imp::metadata(path.as_ref()).map(Metadata)
24132413
}
24142414

24152415
/// Queries the metadata about a file without following symlinks.
@@ -2444,7 +2444,7 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
24442444
#[doc(alias = "lstat")]
24452445
#[stable(feature = "symlink_metadata", since = "1.1.0")]
24462446
pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
2447-
fs_imp::lstat(path.as_ref()).map(Metadata)
2447+
fs_imp::symlink_metadata(path.as_ref()).map(Metadata)
24482448
}
24492449

24502450
/// Renames a file or directory to a new name, replacing the original file if
@@ -2598,7 +2598,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
25982598
#[doc(alias = "CreateHardLink", alias = "linkat")]
25992599
#[stable(feature = "rust1", since = "1.0.0")]
26002600
pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
2601-
fs_imp::link(original.as_ref(), link.as_ref())
2601+
fs_imp::hard_link(original.as_ref(), link.as_ref())
26022602
}
26032603

26042604
/// Creates a new symbolic link on the filesystem.
@@ -2664,7 +2664,7 @@ pub fn soft_link<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Re
26642664
/// ```
26652665
#[stable(feature = "rust1", since = "1.0.0")]
26662666
pub fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
2667-
fs_imp::readlink(path.as_ref())
2667+
fs_imp::read_link(path.as_ref())
26682668
}
26692669

26702670
/// Returns the canonical, absolute form of a path with all intermediate
@@ -2840,7 +2840,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
28402840
#[doc(alias = "rmdir", alias = "RemoveDirectory")]
28412841
#[stable(feature = "rust1", since = "1.0.0")]
28422842
pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
2843-
fs_imp::rmdir(path.as_ref())
2843+
fs_imp::remove_dir(path.as_ref())
28442844
}
28452845

28462846
/// Removes a directory at this path, after removing all its contents. Use
@@ -2967,7 +2967,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
29672967
#[doc(alias = "ls", alias = "opendir", alias = "FindFirstFile", alias = "FindNextFile")]
29682968
#[stable(feature = "rust1", since = "1.0.0")]
29692969
pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
2970-
fs_imp::readdir(path.as_ref()).map(ReadDir)
2970+
fs_imp::read_dir(path.as_ref()).map(ReadDir)
29712971
}
29722972

29732973
/// Changes the permissions found on a file or a directory.
@@ -3003,7 +3003,7 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
30033003
#[doc(alias = "chmod", alias = "SetFileAttributes")]
30043004
#[stable(feature = "set_permissions", since = "1.1.0")]
30053005
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
3006-
fs_imp::set_perm(path.as_ref(), perm.0)
3006+
fs_imp::set_permissions(path.as_ref(), perm.0)
30073007
}
30083008

30093009
impl DirBuilder {

‎library/std/src/sys/fs/mod.rs

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,113 @@
11
#![deny(unsafe_op_in_unsafe_fn)]
22

3+
use crate::io;
4+
use crate::path::{Path, PathBuf};
5+
36
pub mod common;
47

58
cfg_if::cfg_if! {
69
if #[cfg(target_family = "unix")] {
710
mod unix;
8-
pub use unix::*;
11+
use unix as imp;
12+
pub use unix::{chown, fchown, lchown, chroot};
13+
pub(crate) use unix::debug_assert_fd_is_open;
14+
#[cfg(any(target_os = "linux", target_os = "android"))]
15+
pub(crate) use unix::CachedFileMetadata;
16+
use crate::sys::common::small_c_string::run_path_with_cstr as with_native_path;
917
} else if #[cfg(target_os = "windows")] {
1018
mod windows;
11-
pub use windows::*;
19+
use windows as imp;
20+
pub use windows::{symlink_inner, junction_point};
1221
} else if #[cfg(target_os = "hermit")] {
1322
mod hermit;
14-
pub use hermit::*;
23+
use hermit as imp;
1524
} else if #[cfg(target_os = "solid_asp3")] {
1625
mod solid;
17-
pub use solid::*;
26+
use solid as imp;
1827
} else if #[cfg(target_os = "uefi")] {
1928
mod uefi;
20-
pub use uefi::*;
29+
use uefi as imp;
2130
} else if #[cfg(target_os = "wasi")] {
2231
mod wasi;
23-
pub use wasi::*;
32+
use wasi as imp;
2433
} else {
2534
mod unsupported;
26-
pub use unsupported::*;
35+
use unsupported as imp;
2736
}
2837
}
38+
39+
// FIXME: Replace this with platform-specific path conversion functions.
40+
#[cfg(not(target_family = "unix"))]
41+
#[inline]
42+
pub fn with_native_path<T>(path: &Path, f: &dyn Fn(&Path) -> io::Result<T>) -> io::Result<T> {
43+
f(path)
44+
}
45+
46+
pub use imp::{
47+
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions,
48+
ReadDir,
49+
};
50+
51+
pub fn read_dir(path: &Path) -> io::Result<ReadDir> {
52+
// FIXME: use with_native_path
53+
imp::readdir(path)
54+
}
55+
56+
pub fn remove_file(path: &Path) -> io::Result<()> {
57+
with_native_path(path, &imp::unlink)
58+
}
59+
60+
pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
61+
with_native_path(old, &|old| with_native_path(new, &|new| imp::rename(old, new)))
62+
}
63+
64+
pub fn remove_dir(path: &Path) -> io::Result<()> {
65+
with_native_path(path, &imp::rmdir)
66+
}
67+
68+
pub fn remove_dir_all(path: &Path) -> io::Result<()> {
69+
// FIXME: use with_native_path
70+
imp::remove_dir_all(path)
71+
}
72+
73+
pub fn read_link(path: &Path) -> io::Result<PathBuf> {
74+
with_native_path(path, &imp::readlink)
75+
}
76+
77+
pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
78+
with_native_path(original, &|original| {
79+
with_native_path(link, &|link| imp::symlink(original, link))
80+
})
81+
}
82+
83+
pub fn hard_link(original: &Path, link: &Path) -> io::Result<()> {
84+
with_native_path(original, &|original| {
85+
with_native_path(link, &|link| imp::link(original, link))
86+
})
87+
}
88+
89+
pub fn metadata(path: &Path) -> io::Result<FileAttr> {
90+
with_native_path(path, &imp::stat)
91+
}
92+
93+
pub fn symlink_metadata(path: &Path) -> io::Result<FileAttr> {
94+
with_native_path(path, &imp::lstat)
95+
}
96+
97+
pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
98+
with_native_path(path, &|path| imp::set_perm(path, perm.clone()))
99+
}
100+
101+
pub fn canonicalize(path: &Path) -> io::Result<PathBuf> {
102+
with_native_path(path, &imp::canonicalize)
103+
}
104+
105+
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
106+
// FIXME: use with_native_path
107+
imp::copy(from, to)
108+
}
109+
110+
pub fn exists(path: &Path) -> io::Result<bool> {
111+
// FIXME: use with_native_path
112+
imp::exists(path)
113+
}

‎library/std/src/sys/fs/unix.rs

Lines changed: 88 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ cfg_has_statx! {{
155155
enum STATX_STATE{ Unknown = 0, Present, Unavailable }
156156
static STATX_SAVED_STATE: AtomicU8 = AtomicU8::new(STATX_STATE::Unknown as u8);
157157

158-
syscall! {
158+
syscall!(
159159
fn statx(
160160
fd: c_int,
161161
pathname: *const c_char,
162162
flags: c_int,
163163
mask: libc::c_uint,
164-
statxbuf: *mut libc::statx
165-
) -> c_int
166-
}
164+
statxbuf: *mut libc::statx,
165+
) -> c_int;
166+
);
167167

168168
let statx_availability = STATX_SAVED_STATE.load(Ordering::Relaxed);
169169
if statx_availability == STATX_STATE::Unavailable as u8 {
@@ -926,7 +926,7 @@ impl DirEntry {
926926
miri
927927
))]
928928
pub fn metadata(&self) -> io::Result<FileAttr> {
929-
lstat(&self.path())
929+
run_path_with_cstr(&self.path(), &lstat)
930930
}
931931

932932
#[cfg(any(
@@ -1540,7 +1540,9 @@ impl File {
15401540
let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?];
15411541
// futimens requires Android API level 19
15421542
cvt(unsafe {
1543-
weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
1543+
weak!(
1544+
fn futimens(fd: c_int, times: *const libc::timespec) -> c_int;
1545+
);
15441546
match futimens.get() {
15451547
Some(futimens) => futimens(self.as_raw_fd(), times.as_ptr()),
15461548
None => return Err(io::const_error!(
@@ -1556,7 +1558,9 @@ impl File {
15561558
use crate::sys::{time::__timespec64, weak::weak};
15571559

15581560
// Added in glibc 2.34
1559-
weak!(fn __futimens64(libc::c_int, *const __timespec64) -> libc::c_int);
1561+
weak!(
1562+
fn __futimens64(fd: c_int, times: *const __timespec64) -> c_int;
1563+
);
15601564

15611565
if let Some(futimens64) = __futimens64.get() {
15621566
let to_timespec = |time: Option<SystemTime>| time.map(|time| time.t.to_timespec64())
@@ -1653,7 +1657,7 @@ impl fmt::Debug for File {
16531657
fn get_path(fd: c_int) -> Option<PathBuf> {
16541658
let mut p = PathBuf::from("/proc/self/fd");
16551659
p.push(&fd.to_string());
1656-
readlink(&p).ok()
1660+
run_path_with_cstr(&p, &readlink).ok()
16571661
}
16581662

16591663
#[cfg(any(target_vendor = "apple", target_os = "netbsd"))]
@@ -1826,127 +1830,106 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
18261830
}
18271831
}
18281832

1829-
pub fn unlink(p: &Path) -> io::Result<()> {
1830-
run_path_with_cstr(p, &|p| cvt(unsafe { libc::unlink(p.as_ptr()) }).map(|_| ()))
1833+
pub fn unlink(p: &CStr) -> io::Result<()> {
1834+
cvt(unsafe { libc::unlink(p.as_ptr()) }).map(|_| ())
18311835
}
18321836

1833-
pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
1834-
run_path_with_cstr(old, &|old| {
1835-
run_path_with_cstr(new, &|new| {
1836-
cvt(unsafe { libc::rename(old.as_ptr(), new.as_ptr()) }).map(|_| ())
1837-
})
1838-
})
1837+
pub fn rename(old: &CStr, new: &CStr) -> io::Result<()> {
1838+
cvt(unsafe { libc::rename(old.as_ptr(), new.as_ptr()) }).map(|_| ())
18391839
}
18401840

1841-
pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
1842-
run_path_with_cstr(p, &|p| cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) }).map(|_| ()))
1841+
pub fn set_perm(p: &CStr, perm: FilePermissions) -> io::Result<()> {
1842+
cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) }).map(|_| ())
18431843
}
18441844

1845-
pub fn rmdir(p: &Path) -> io::Result<()> {
1846-
run_path_with_cstr(p, &|p| cvt(unsafe { libc::rmdir(p.as_ptr()) }).map(|_| ()))
1845+
pub fn rmdir(p: &CStr) -> io::Result<()> {
1846+
cvt(unsafe { libc::rmdir(p.as_ptr()) }).map(|_| ())
18471847
}
18481848

1849-
pub fn readlink(p: &Path) -> io::Result<PathBuf> {
1850-
run_path_with_cstr(p, &|c_path| {
1851-
let p = c_path.as_ptr();
1849+
pub fn readlink(c_path: &CStr) -> io::Result<PathBuf> {
1850+
let p = c_path.as_ptr();
18521851

1853-
let mut buf = Vec::with_capacity(256);
1852+
let mut buf = Vec::with_capacity(256);
18541853

1855-
loop {
1856-
let buf_read =
1857-
cvt(unsafe { libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity()) })?
1858-
as usize;
1859-
1860-
unsafe {
1861-
buf.set_len(buf_read);
1862-
}
1854+
loop {
1855+
let buf_read =
1856+
cvt(unsafe { libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity()) })? as usize;
18631857

1864-
if buf_read != buf.capacity() {
1865-
buf.shrink_to_fit();
1858+
unsafe {
1859+
buf.set_len(buf_read);
1860+
}
18661861

1867-
return Ok(PathBuf::from(OsString::from_vec(buf)));
1868-
}
1862+
if buf_read != buf.capacity() {
1863+
buf.shrink_to_fit();
18691864

1870-
// Trigger the internal buffer resizing logic of `Vec` by requiring
1871-
// more space than the current capacity. The length is guaranteed to be
1872-
// the same as the capacity due to the if statement above.
1873-
buf.reserve(1);
1865+
return Ok(PathBuf::from(OsString::from_vec(buf)));
18741866
}
1875-
})
1867+
1868+
// Trigger the internal buffer resizing logic of `Vec` by requiring
1869+
// more space than the current capacity. The length is guaranteed to be
1870+
// the same as the capacity due to the if statement above.
1871+
buf.reserve(1);
1872+
}
18761873
}
18771874

1878-
pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
1879-
run_path_with_cstr(original, &|original| {
1880-
run_path_with_cstr(link, &|link| {
1881-
cvt(unsafe { libc::symlink(original.as_ptr(), link.as_ptr()) }).map(|_| ())
1882-
})
1883-
})
1875+
pub fn symlink(original: &CStr, link: &CStr) -> io::Result<()> {
1876+
cvt(unsafe { libc::symlink(original.as_ptr(), link.as_ptr()) }).map(|_| ())
18841877
}
18851878

1886-
pub fn link(original: &Path, link: &Path) -> io::Result<()> {
1887-
run_path_with_cstr(original, &|original| {
1888-
run_path_with_cstr(link, &|link| {
1889-
cfg_if::cfg_if! {
1890-
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon", target_os = "vita", target_env = "nto70"))] {
1891-
// VxWorks, Redox and ESP-IDF lack `linkat`, so use `link` instead. POSIX leaves
1892-
// it implementation-defined whether `link` follows symlinks, so rely on the
1893-
// `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
1894-
// Android has `linkat` on newer versions, but we happen to know `link`
1895-
// always has the correct behavior, so it's here as well.
1896-
cvt(unsafe { libc::link(original.as_ptr(), link.as_ptr()) })?;
1897-
} else {
1898-
// Where we can, use `linkat` instead of `link`; see the comment above
1899-
// this one for details on why.
1900-
cvt(unsafe { libc::linkat(libc::AT_FDCWD, original.as_ptr(), libc::AT_FDCWD, link.as_ptr(), 0) })?;
1901-
}
1902-
}
1903-
Ok(())
1904-
})
1905-
})
1879+
pub fn link(original: &CStr, link: &CStr) -> io::Result<()> {
1880+
cfg_if::cfg_if! {
1881+
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon", target_os = "vita", target_env = "nto70"))] {
1882+
// VxWorks, Redox and ESP-IDF lack `linkat`, so use `link` instead. POSIX leaves
1883+
// it implementation-defined whether `link` follows symlinks, so rely on the
1884+
// `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
1885+
// Android has `linkat` on newer versions, but we happen to know `link`
1886+
// always has the correct behavior, so it's here as well.
1887+
cvt(unsafe { libc::link(original.as_ptr(), link.as_ptr()) })?;
1888+
} else {
1889+
// Where we can, use `linkat` instead of `link`; see the comment above
1890+
// this one for details on why.
1891+
cvt(unsafe { libc::linkat(libc::AT_FDCWD, original.as_ptr(), libc::AT_FDCWD, link.as_ptr(), 0) })?;
1892+
}
1893+
}
1894+
Ok(())
19061895
}
19071896

1908-
pub fn stat(p: &Path) -> io::Result<FileAttr> {
1909-
run_path_with_cstr(p, &|p| {
1910-
cfg_has_statx! {
1911-
if let Some(ret) = unsafe { try_statx(
1912-
libc::AT_FDCWD,
1913-
p.as_ptr(),
1914-
libc::AT_STATX_SYNC_AS_STAT,
1915-
libc::STATX_BASIC_STATS | libc::STATX_BTIME,
1916-
) } {
1917-
return ret;
1918-
}
1897+
pub fn stat(p: &CStr) -> io::Result<FileAttr> {
1898+
cfg_has_statx! {
1899+
if let Some(ret) = unsafe { try_statx(
1900+
libc::AT_FDCWD,
1901+
p.as_ptr(),
1902+
libc::AT_STATX_SYNC_AS_STAT,
1903+
libc::STATX_BASIC_STATS | libc::STATX_BTIME,
1904+
) } {
1905+
return ret;
19191906
}
1907+
}
19201908

1921-
let mut stat: stat64 = unsafe { mem::zeroed() };
1922-
cvt(unsafe { stat64(p.as_ptr(), &mut stat) })?;
1923-
Ok(FileAttr::from_stat64(stat))
1924-
})
1909+
let mut stat: stat64 = unsafe { mem::zeroed() };
1910+
cvt(unsafe { stat64(p.as_ptr(), &mut stat) })?;
1911+
Ok(FileAttr::from_stat64(stat))
19251912
}
19261913

1927-
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
1928-
run_path_with_cstr(p, &|p| {
1929-
cfg_has_statx! {
1930-
if let Some(ret) = unsafe { try_statx(
1931-
libc::AT_FDCWD,
1932-
p.as_ptr(),
1933-
libc::AT_SYMLINK_NOFOLLOW | libc::AT_STATX_SYNC_AS_STAT,
1934-
libc::STATX_BASIC_STATS | libc::STATX_BTIME,
1935-
) } {
1936-
return ret;
1937-
}
1914+
pub fn lstat(p: &CStr) -> io::Result<FileAttr> {
1915+
cfg_has_statx! {
1916+
if let Some(ret) = unsafe { try_statx(
1917+
libc::AT_FDCWD,
1918+
p.as_ptr(),
1919+
libc::AT_SYMLINK_NOFOLLOW | libc::AT_STATX_SYNC_AS_STAT,
1920+
libc::STATX_BASIC_STATS | libc::STATX_BTIME,
1921+
) } {
1922+
return ret;
19381923
}
1924+
}
19391925

1940-
let mut stat: stat64 = unsafe { mem::zeroed() };
1941-
cvt(unsafe { lstat64(p.as_ptr(), &mut stat) })?;
1942-
Ok(FileAttr::from_stat64(stat))
1943-
})
1926+
let mut stat: stat64 = unsafe { mem::zeroed() };
1927+
cvt(unsafe { lstat64(p.as_ptr(), &mut stat) })?;
1928+
Ok(FileAttr::from_stat64(stat))
19441929
}
19451930

1946-
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
1947-
let r = run_path_with_cstr(p, &|path| unsafe {
1948-
Ok(libc::realpath(path.as_ptr(), ptr::null_mut()))
1949-
})?;
1931+
pub fn canonicalize(path: &CStr) -> io::Result<PathBuf> {
1932+
let r = unsafe { libc::realpath(path.as_ptr(), ptr::null_mut()) };
19501933
if r.is_null() {
19511934
return Err(io::Error::last_os_error());
19521935
}
@@ -2324,19 +2307,19 @@ mod remove_dir_impl {
23242307
Ok(())
23252308
}
23262309

2327-
fn remove_dir_all_modern(p: &Path) -> io::Result<()> {
2310+
fn remove_dir_all_modern(p: &CStr) -> io::Result<()> {
23282311
// We cannot just call remove_dir_all_recursive() here because that would not delete a passed
23292312
// symlink. No need to worry about races, because remove_dir_all_recursive() does not recurse
23302313
// into symlinks.
23312314
let attr = lstat(p)?;
23322315
if attr.file_type().is_symlink() {
2333-
crate::fs::remove_file(p)
2316+
super::unlink(p)
23342317
} else {
2335-
run_path_with_cstr(p, &|p| remove_dir_all_recursive(None, &p))
2318+
remove_dir_all_recursive(None, &p)
23362319
}
23372320
}
23382321

23392322
pub fn remove_dir_all(p: &Path) -> io::Result<()> {
2340-
remove_dir_all_modern(p)
2323+
run_path_with_cstr(p, &remove_dir_all_modern)
23412324
}
23422325
}

‎library/std/src/sys/pal/unix/fd.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ impl FileDesc {
232232
// implementation if `preadv` is not available.
233233
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
234234
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
235-
super::weak::syscall! {
235+
super::weak::syscall!(
236236
fn preadv(
237237
fd: libc::c_int,
238238
iovec: *const libc::iovec,
239239
n_iovec: libc::c_int,
240-
offset: off64_t
241-
) -> isize
242-
}
240+
offset: off64_t,
241+
) -> isize;
242+
);
243243

244244
let ret = cvt(unsafe {
245245
preadv(
@@ -257,7 +257,14 @@ impl FileDesc {
257257
// and its metadata from LLVM IR.
258258
#[no_sanitize(cfi)]
259259
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
260-
super::weak::weak!(fn preadv64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
260+
super::weak::weak!(
261+
fn preadv64(
262+
fd: libc::c_int,
263+
iovec: *const libc::iovec,
264+
n_iovec: libc::c_int,
265+
offset: off64_t,
266+
) -> isize;
267+
);
261268

262269
match preadv64.get() {
263270
Some(preadv) => {
@@ -286,7 +293,14 @@ impl FileDesc {
286293
// use "weak" linking.
287294
#[cfg(target_vendor = "apple")]
288295
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
289-
super::weak::weak!(fn preadv(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
296+
super::weak::weak!(
297+
fn preadv(
298+
fd: libc::c_int,
299+
iovec: *const libc::iovec,
300+
n_iovec: libc::c_int,
301+
offset: off64_t,
302+
) -> isize;
303+
);
290304

291305
match preadv.get() {
292306
Some(preadv) => {
@@ -428,14 +442,14 @@ impl FileDesc {
428442
// implementation if `pwritev` is not available.
429443
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
430444
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
431-
super::weak::syscall! {
445+
super::weak::syscall!(
432446
fn pwritev(
433447
fd: libc::c_int,
434448
iovec: *const libc::iovec,
435449
n_iovec: libc::c_int,
436-
offset: off64_t
437-
) -> isize
438-
}
450+
offset: off64_t,
451+
) -> isize;
452+
);
439453

440454
let ret = cvt(unsafe {
441455
pwritev(
@@ -450,7 +464,14 @@ impl FileDesc {
450464

451465
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
452466
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
453-
super::weak::weak!(fn pwritev64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
467+
super::weak::weak!(
468+
fn pwritev64(
469+
fd: libc::c_int,
470+
iovec: *const libc::iovec,
471+
n_iovec: libc::c_int,
472+
offset: off64_t,
473+
) -> isize;
474+
);
454475

455476
match pwritev64.get() {
456477
Some(pwritev) => {
@@ -479,7 +500,14 @@ impl FileDesc {
479500
// use "weak" linking.
480501
#[cfg(target_vendor = "apple")]
481502
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
482-
super::weak::weak!(fn pwritev(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
503+
super::weak::weak!(
504+
fn pwritev(
505+
fd: libc::c_int,
506+
iovec: *const libc::iovec,
507+
n_iovec: libc::c_int,
508+
offset: off64_t,
509+
) -> isize;
510+
);
483511

484512
match pwritev.get() {
485513
Some(pwritev) => {

‎library/std/src/sys/pal/unix/kernel_copy.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,16 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) ->
604604
_ => true,
605605
};
606606

607-
syscall! {
607+
syscall!(
608608
fn copy_file_range(
609609
fd_in: libc::c_int,
610610
off_in: *mut libc::loff_t,
611611
fd_out: libc::c_int,
612612
off_out: *mut libc::loff_t,
613613
len: libc::size_t,
614-
flags: libc::c_uint
615-
) -> libc::ssize_t
616-
}
614+
flags: libc::c_uint,
615+
) -> libc::ssize_t;
616+
);
617617

618618
fn probe_copy_file_range_support() -> u8 {
619619
// In some cases, we cannot determine availability from the first
@@ -727,16 +727,16 @@ fn sendfile_splice(mode: SpliceMode, reader: RawFd, writer: RawFd, len: u64) ->
727727
// Android builds use feature level 14, but the libc wrapper for splice is
728728
// gated on feature level 21+, so we have to invoke the syscall directly.
729729
#[cfg(target_os = "android")]
730-
syscall! {
730+
syscall!(
731731
fn splice(
732732
srcfd: libc::c_int,
733733
src_offset: *const i64,
734734
dstfd: libc::c_int,
735735
dst_offset: *const i64,
736736
len: libc::size_t,
737-
flags: libc::c_int
738-
) -> libc::ssize_t
739-
}
737+
flags: libc::c_int,
738+
) -> libc::ssize_t;
739+
);
740740

741741
#[cfg(target_os = "linux")]
742742
use libc::splice;

‎library/std/src/sys/pal/unix/stack_overflow.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,32 @@ mod imp {
424424

425425
let pages = PAGES.get_or_init(|| {
426426
use crate::sys::weak::dlsym;
427-
dlsym!(fn sysctlbyname(*const libc::c_char, *mut libc::c_void, *mut libc::size_t, *const libc::c_void, libc::size_t) -> libc::c_int);
427+
dlsym!(
428+
fn sysctlbyname(
429+
name: *const libc::c_char,
430+
oldp: *mut libc::c_void,
431+
oldlenp: *mut libc::size_t,
432+
newp: *const libc::c_void,
433+
newlen: libc::size_t,
434+
) -> libc::c_int;
435+
);
428436
let mut guard: usize = 0;
429437
let mut size = size_of_val(&guard);
430438
let oid = c"security.bsd.stack_guard_page";
431439
match sysctlbyname.get() {
432-
Some(fcn) if unsafe {
433-
fcn(oid.as_ptr(),
434-
(&raw mut guard).cast(),
435-
&raw mut size,
436-
ptr::null_mut(),
437-
0) == 0
438-
} => guard,
440+
Some(fcn)
441+
if unsafe {
442+
fcn(
443+
oid.as_ptr(),
444+
(&raw mut guard).cast(),
445+
&raw mut size,
446+
ptr::null_mut(),
447+
0,
448+
) == 0
449+
} =>
450+
{
451+
guard
452+
}
439453
_ => 1,
440454
}
441455
});

‎library/std/src/sys/pal/unix/thread.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ impl Thread {
193193
// and its metadata from LLVM IR.
194194
#[no_sanitize(cfi)]
195195
pub fn set_name(name: &CStr) {
196-
weak! {
196+
weak!(
197197
fn pthread_setname_np(
198-
libc::pthread_t, *const libc::c_char
199-
) -> libc::c_int
200-
}
198+
thread: libc::pthread_t,
199+
name: *const libc::c_char,
200+
) -> libc::c_int;
201+
);
201202

202203
if let Some(f) = pthread_setname_np.get() {
203204
#[cfg(target_os = "nto")]
@@ -762,7 +763,9 @@ unsafe fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize {
762763
// We use dlsym to avoid an ELF version dependency on GLIBC_PRIVATE. (#23628)
763764
// We shouldn't really be using such an internal symbol, but there's currently
764765
// no other way to account for the TLS size.
765-
dlsym!(fn __pthread_get_minstack(*const libc::pthread_attr_t) -> libc::size_t);
766+
dlsym!(
767+
fn __pthread_get_minstack(attr: *const libc::pthread_attr_t) -> libc::size_t;
768+
);
766769

767770
match __pthread_get_minstack.get() {
768771
None => libc::PTHREAD_STACK_MIN,

‎library/std/src/sys/pal/unix/time.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ impl Timespec {
123123

124124
// __clock_gettime64 was added to 32-bit arches in glibc 2.34,
125125
// and it handles both vDSO calls and ENOSYS fallbacks itself.
126-
weak!(fn __clock_gettime64(libc::clockid_t, *mut __timespec64) -> libc::c_int);
126+
weak!(
127+
fn __clock_gettime64(
128+
clockid: libc::clockid_t,
129+
tp: *mut __timespec64,
130+
) -> libc::c_int;
131+
);
127132

128133
if let Some(clock_gettime64) = __clock_gettime64.get() {
129134
let mut t = MaybeUninit::uninit();

‎library/std/src/sys/pal/unix/weak.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{mem, ptr};
2929
// We can use true weak linkage on ELF targets.
3030
#[cfg(all(unix, not(target_vendor = "apple")))]
3131
pub(crate) macro weak {
32-
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
32+
(fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => (
3333
let ref $name: ExternWeak<unsafe extern "C" fn($($t),*) -> $ret> = {
3434
unsafe extern "C" {
3535
#[linkage = "extern_weak"]
@@ -62,10 +62,16 @@ impl<F: Copy> ExternWeak<F> {
6262
}
6363

6464
pub(crate) macro dlsym {
65-
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
66-
dlsym!(fn $name($($t),*) -> $ret, stringify!($name));
65+
(fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => (
66+
dlsym!(
67+
#[link_name = stringify!($name)]
68+
fn $name($($param : $t),*) -> $ret;
69+
);
6770
),
68-
(fn $name:ident($($t:ty),*) -> $ret:ty, $sym:expr) => (
71+
(
72+
#[link_name = $sym:expr]
73+
fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;
74+
) => (
6975
static DLSYM: DlsymWeak<unsafe extern "C" fn($($t),*) -> $ret> =
7076
DlsymWeak::new(concat!($sym, '\0'));
7177
let $name = &DLSYM;
@@ -143,15 +149,15 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
143149

144150
#[cfg(not(any(target_os = "linux", target_os = "android")))]
145151
pub(crate) macro syscall {
146-
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
152+
(fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => (
147153
// FIXME(#115199): Rust currently omits weak function definitions
148154
// and its metadata from LLVM IR.
149155
#[no_sanitize(cfi)]
150-
unsafe fn $name($($arg_name: $t),*) -> $ret {
151-
weak! { fn $name($($t),*) -> $ret }
156+
unsafe fn $name($($param: $t),*) -> $ret {
157+
weak!(fn $name($($param: $t),*) -> $ret;);
152158

153159
if let Some(fun) = $name.get() {
154-
fun($($arg_name),*)
160+
fun($($param),*)
155161
} else {
156162
super::os::set_errno(libc::ENOSYS);
157163
-1
@@ -162,26 +168,28 @@ pub(crate) macro syscall {
162168

163169
#[cfg(any(target_os = "linux", target_os = "android"))]
164170
pub(crate) macro syscall {
165-
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
166-
unsafe fn $name($($arg_name:$t),*) -> $ret {
167-
weak! { fn $name($($t),*) -> $ret }
171+
(
172+
fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;
173+
) => (
174+
unsafe fn $name($($param: $t),*) -> $ret {
175+
weak!(fn $name($($param: $t),*) -> $ret;);
168176

169177
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
170178
// interposition, but if it's not found just use a raw syscall.
171179
if let Some(fun) = $name.get() {
172-
fun($($arg_name),*)
180+
fun($($param),*)
173181
} else {
174-
libc::syscall(libc::${concat(SYS_, $name)}, $($arg_name),*) as $ret
182+
libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret
175183
}
176184
}
177185
)
178186
}
179187

180188
#[cfg(any(target_os = "linux", target_os = "android"))]
181189
pub(crate) macro raw_syscall {
182-
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
183-
unsafe fn $name($($arg_name:$t),*) -> $ret {
184-
libc::syscall(libc::${concat(SYS_, $name)}, $($arg_name),*) as $ret
190+
(fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => (
191+
unsafe fn $name($($param: $t),*) -> $ret {
192+
libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret
185193
}
186194
)
187195
}

‎library/std/src/sys/pal/wasi/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ cfg_if::cfg_if! {
6767
}
6868
}
6969

70-
pub const DEFAULT_MIN_STACK_SIZE: usize = 64 * 1024;
70+
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
7171

7272
impl Thread {
7373
// unsafe: see thread::Builder::spawn_unchecked for safety requirements

‎library/std/src/sys/pal/wasm/atomics/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::time::Duration;
66

77
pub struct Thread(!);
88

9-
pub const DEFAULT_MIN_STACK_SIZE: usize = 64 * 1024;
9+
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
1010

1111
impl Thread {
1212
// unsafe: see thread::Builder::spawn_unchecked for safety requirements

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,20 @@ impl Command {
461461
if #[cfg(target_os = "linux")] {
462462
use crate::sys::weak::weak;
463463

464-
weak! {
464+
weak!(
465465
fn pidfd_spawnp(
466-
*mut libc::c_int,
467-
*const libc::c_char,
468-
*const libc::posix_spawn_file_actions_t,
469-
*const libc::posix_spawnattr_t,
470-
*const *mut libc::c_char,
471-
*const *mut libc::c_char
472-
) -> libc::c_int
473-
}
466+
pidfd: *mut libc::c_int,
467+
path: *const libc::c_char,
468+
file_actions: *const libc::posix_spawn_file_actions_t,
469+
attrp: *const libc::posix_spawnattr_t,
470+
argv: *const *mut libc::c_char,
471+
envp: *const *mut libc::c_char,
472+
) -> libc::c_int;
473+
);
474474

475-
weak! { fn pidfd_getpid(libc::c_int) -> libc::c_int }
475+
weak!(
476+
fn pidfd_getpid(pidfd: libc::c_int) -> libc::c_int;
477+
);
476478

477479
static PIDFD_SUPPORTED: AtomicU8 = AtomicU8::new(0);
478480
const UNKNOWN: u8 = 0;
@@ -593,19 +595,19 @@ impl Command {
593595
// https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_addchdir.html.
594596
// The _np version is more widely available, though, so try that first.
595597

596-
weak! {
598+
weak!(
597599
fn posix_spawn_file_actions_addchdir_np(
598-
*mut libc::posix_spawn_file_actions_t,
599-
*const libc::c_char
600-
) -> libc::c_int
601-
}
600+
file_actions: *mut libc::posix_spawn_file_actions_t,
601+
path: *const libc::c_char,
602+
) -> libc::c_int;
603+
);
602604

603-
weak! {
605+
weak!(
604606
fn posix_spawn_file_actions_addchdir(
605-
*mut libc::posix_spawn_file_actions_t,
606-
*const libc::c_char
607-
) -> libc::c_int
608-
}
607+
file_actions: *mut libc::posix_spawn_file_actions_t,
608+
path: *const libc::c_char,
609+
) -> libc::c_int;
610+
);
609611

610612
posix_spawn_file_actions_addchdir_np
611613
.get()

‎library/std/src/sys/random/linux.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
7373
// A weak symbol allows interposition, e.g. for perf measurements that want to
7474
// disable randomness for consistency. Otherwise, we'll try a raw syscall.
7575
// (`getrandom` was added in glibc 2.25, musl 1.1.20, android API level 28)
76-
syscall! {
76+
syscall!(
7777
fn getrandom(
7878
buffer: *mut libc::c_void,
7979
length: libc::size_t,
80-
flags: libc::c_uint
81-
) -> libc::ssize_t
82-
}
80+
flags: libc::c_uint,
81+
) -> libc::ssize_t;
82+
);
8383

8484
static GETRANDOM_AVAILABLE: AtomicBool = AtomicBool::new(true);
8585
static GRND_INSECURE_AVAILABLE: AtomicBool = AtomicBool::new(true);

‎src/bootstrap/src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn check_version(config: &Config) -> Option<String> {
191191
}
192192

193193
msg.push_str("There have been changes to x.py since you last updated:\n");
194-
msg.push_str(&human_readable_changes(&changes));
194+
msg.push_str(&human_readable_changes(changes));
195195

196196
msg.push_str("NOTE: to silence this warning, ");
197197
msg.push_str(&format!(

‎src/bootstrap/src/core/config/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ impl Config {
13811381
if !changes.is_empty() {
13821382
println!(
13831383
"WARNING: There have been changes to x.py since you last updated:\n{}",
1384-
crate::human_readable_changes(&changes)
1384+
crate::human_readable_changes(changes)
13851385
);
13861386
}
13871387
}

‎src/bootstrap/src/utils/change_tracker.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,25 @@ impl Display for ChangeSeverity {
3535
}
3636
}
3737

38-
pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> {
39-
if !CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == current_id) {
38+
pub fn find_recent_config_change_ids(current_id: usize) -> &'static [ChangeInfo] {
39+
if let Some(index) =
40+
CONFIG_CHANGE_HISTORY.iter().position(|config| config.change_id == current_id)
41+
{
42+
// Skip the current_id and IDs before it
43+
&CONFIG_CHANGE_HISTORY[index + 1..]
44+
} else {
4045
// If the current change-id is greater than the most recent one, return
4146
// an empty list (it may be due to switching from a recent branch to an
4247
// older one); otherwise, return the full list (assuming the user provided
4348
// the incorrect change-id by accident).
4449
if let Some(config) = CONFIG_CHANGE_HISTORY.iter().max_by_key(|config| config.change_id) {
4550
if current_id > config.change_id {
46-
return Vec::new();
51+
return &[];
4752
}
4853
}
4954

50-
return CONFIG_CHANGE_HISTORY.to_vec();
55+
CONFIG_CHANGE_HISTORY
5156
}
52-
53-
let index =
54-
CONFIG_CHANGE_HISTORY.iter().position(|config| config.change_id == current_id).unwrap();
55-
56-
CONFIG_CHANGE_HISTORY
57-
.iter()
58-
.skip(index + 1) // Skip the current_id and IDs before it
59-
.cloned()
60-
.collect()
6157
}
6258

6359
pub fn human_readable_changes(changes: &[ChangeInfo]) -> String {

‎src/tools/compiletest/src/header.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,14 @@ fn iter_header(
924924

925925
impl Config {
926926
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
927-
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
927+
const FORBIDDEN_REVISION_NAMES: [&str; 2] = [
928+
// `//@ revisions: true false` Implying `--cfg=true` and `--cfg=false` makes it very
929+
// weird for the test, since if the test writer wants a cfg of the same revision name
930+
// they'd have to use `cfg(r#true)` and `cfg(r#false)`.
931+
"true", "false",
932+
];
933+
934+
const FILECHECK_FORBIDDEN_REVISION_NAMES: [&str; 9] =
928935
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
929936

930937
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
@@ -933,25 +940,38 @@ impl Config {
933940
}
934941

935942
let mut duplicates: HashSet<_> = existing.iter().cloned().collect();
936-
for revision in raw.split_whitespace().map(|r| r.to_string()) {
937-
if !duplicates.insert(revision.clone()) {
943+
for revision in raw.split_whitespace() {
944+
if !duplicates.insert(revision.to_string()) {
938945
panic!(
939946
"duplicate revision: `{}` in line `{}`: {}",
940947
revision,
941948
raw,
942949
testfile.display()
943950
);
944-
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
945-
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
951+
}
952+
953+
if FORBIDDEN_REVISION_NAMES.contains(&revision) {
954+
panic!(
955+
"revision name `{revision}` is not permitted: `{}` in line `{}`: {}",
956+
revision,
957+
raw,
958+
testfile.display()
959+
);
960+
}
961+
962+
if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
963+
&& FILECHECK_FORBIDDEN_REVISION_NAMES.contains(&revision)
946964
{
947965
panic!(
948-
"revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\
949-
as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}",
966+
"revision name `{revision}` is not permitted in a test suite that uses \
967+
`FileCheck` annotations as it is confusing when used as custom `FileCheck` \
968+
prefix: `{revision}` in line `{}`: {}",
950969
raw,
951970
testfile.display()
952971
);
953972
}
954-
existing.push(revision);
973+
974+
existing.push(revision.to_string());
955975
}
956976
}
957977
}

‎src/tools/compiletest/src/header/tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,13 @@ fn test_assembly_mode_forbidden_revisions() {
567567
parse_rs(&config, "//@ revisions: CHECK");
568568
}
569569

570+
#[test]
571+
#[should_panic(expected = "revision name `true` is not permitted")]
572+
fn test_forbidden_revisions() {
573+
let config = cfg().mode("ui").build();
574+
parse_rs(&config, "//@ revisions: true");
575+
}
576+
570577
#[test]
571578
#[should_panic(
572579
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"

0 commit comments

Comments
 (0)
This repository has been archived.