Skip to content

Commit ef8b5e1

Browse files
committed
Auto merge of rust-lang#139096 - jhpratt:rollup-nfyct4q, r=jhpratt
Rollup of 7 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#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 928468c + 03c6f83 commit ef8b5e1

File tree

28 files changed

+272
-223
lines changed

28 files changed

+272
-223
lines changed

compiler/rustc_builtin_macros/src/edition_panic.rs

+5-5
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

+1-1
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

+1-1
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

+49-93
Large diffs are not rendered by default.

compiler/rustc_hir_typeck/src/upvar.rs

+5-5
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

+8-2
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

+1-1
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

+1-1
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

+6-5
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

+1-1
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

+1-2
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

+1-1
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/sys/fs/unix.rs

+10-6
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 {
@@ -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())

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

+40-12
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

+8-8
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

+22-8
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

+8-5
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,

0 commit comments

Comments
 (0)