Skip to content

Rollup of 7 pull requests #139101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bf37447
Reject `{true,false}` as revision names
jieyouxu Mar 19, 2025
38cf49d
wasm: increase default thread stack size to 1 MB
surban Mar 20, 2025
a7bafc0
Change the syntax of the internal `weak!` macro
madsmtm Mar 26, 2025
a86e0da
doc(hir::Place): clarify that places aren't always place expressions
meithecatte Feb 26, 2025
376c88e
ExprUseVisitor: add clarifying doc comments
meithecatte Feb 26, 2025
aab1293
ExprUseVisitor: error -> bug in helper names
meithecatte Feb 26, 2025
f161953
ExprUseVisitor: remove leftover mentions of mem-categorization
meithecatte Feb 26, 2025
908504e
ExprUseVisitor: use tracing::instrument as appropriate
meithecatte Mar 26, 2025
827cb1b
use `try_fold` instead of `fold`
yotamofek Mar 28, 2025
9ef35dd
use `slice::contains` where applicable
yotamofek Mar 28, 2025
163ea4a
Add more tests for pin!().
m-ou-se Mar 28, 2025
240a4da
Rollup merge of #138692 - jieyouxu:reject-bool-lit-rev-names, r=wesle…
matthiaskrgr Mar 29, 2025
c82b88b
Rollup merge of #138757 - rust-wasi-web:wasi-thread-stack-size, r=ale…
matthiaskrgr Mar 29, 2025
111351f
Rollup merge of #138988 - madsmtm:internal-weak-macro-syntax, r=ibrah…
matthiaskrgr Mar 29, 2025
0e722cc
Rollup merge of #139056 - yotamofek:pr/smir/try_fold, r=scottmcm
matthiaskrgr Mar 29, 2025
b5ad69b
Rollup merge of #139057 - yotamofek:pr/slice-contains, r=wesleywiser
matthiaskrgr Mar 29, 2025
12165fc
Rollup merge of #139086 - meithecatte:expr-use-visitor-cleanup, r=com…
matthiaskrgr Mar 29, 2025
8b7088a
Rollup merge of #139097 - m-ou-se:pin-tests, r=WaffleLapkin
matthiaskrgr Mar 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_builtin_macros/src/edition_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub(crate) fn use_panic_2021(mut span: Span) -> bool {
// (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
loop {
let expn = span.ctxt().outer_expn_data();
if let Some(features) = expn.allow_internal_unstable {
if features.iter().any(|&f| f == sym::edition_panic) {
span = expn.call_site;
continue;
}
if let Some(features) = expn.allow_internal_unstable
&& features.contains(&sym::edition_panic)
{
span = expn.call_site;
continue;
}
break expn.edition >= Edition::Edition2021;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
// indirectly from ThinLTO. In theory these are not needed as ThinLTO could resolve
// these, but it currently does not do so.
let can_have_static_objects =
tcx.sess.lto() == Lto::Thin || tcx.crate_types().iter().any(|ct| *ct == CrateType::Rlib);
tcx.sess.lto() == Lto::Thin || tcx.crate_types().contains(&CrateType::Rlib);

tcx.sess.target.is_like_windows &&
can_have_static_objects &&
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if let Some((name, _)) = lang_items::extract(attrs)
&& let Some(lang_item) = LangItem::from_name(name)
{
if WEAK_LANG_ITEMS.iter().any(|&l| l == lang_item) {
if WEAK_LANG_ITEMS.contains(&lang_item) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
}
if let Some(link_name) = lang_item.link_name() {
Expand Down
142 changes: 49 additions & 93 deletions compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
//! from there).
//!
//! The fact that we are inferring borrow kinds as we go results in a
//! semi-hacky interaction with mem-categorization. In particular,
//! mem-categorization will query the current borrow kind as it
//! categorizes, and we'll return the *current* value, but this may get
//! semi-hacky interaction with the way `ExprUseVisitor` is computing
//! `Place`s. In particular, it will query the current borrow kind as it
//! goes, and we'll return the *current* value, but this may get
//! adjusted later. Therefore, in this module, we generally ignore the
//! borrow kind (and derived mutabilities) that are returned from
//! mem-categorization, since they may be inaccurate. (Another option
//! borrow kind (and derived mutabilities) that `ExprUseVisitor` returns
//! within `Place`s, since they may be inaccurate. (Another option
//! would be to use a unification scheme, where instead of returning a
//! concrete borrow kind like `ty::ImmBorrow`, we return a
//! `ty::InferBorrow(upvar_id)` or something like that, but this would
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_middle/src/hir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub struct Projection<'tcx> {
pub kind: ProjectionKind,
}

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

/// A `PlaceWithHirId` represents how a value is located in memory.
/// A `PlaceWithHirId` represents how a value is located in memory. This does not
/// always correspond to a syntactic place expression. For example, when
/// processing a pattern, a `Place` can be used to refer to the sub-value
/// currently being inspected.
///
/// This is an HIR version of [`rustc_middle::mir::Place`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/builder/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ fn build_scope_drops<'tcx>(
// path, then don't generate the drop. (We only take this into
// account for non-unwind paths so as not to disturb the
// caching mechanism.)
if scope.moved_locals.iter().any(|&o| o == local) {
if scope.moved_locals.contains(&local) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct EntryContext<'tcx> {
}

fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
let any_exe = tcx.crate_types().iter().any(|ty| *ty == CrateType::Executable);
let any_exe = tcx.crate_types().contains(&CrateType::Executable);
if !any_exe {
// No need to find a main function.
return None;
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_session/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ pub fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
arg[a.len()..].to_string()
};
let option = content.split_once('=').map(|s| s.0).unwrap_or(&content);
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.iter().any(|exc| option == *exc) {
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.contains(&option) {
excluded_cargo_defaults = true;
} else {
result.push(a.to_string());
match ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.iter().find(|s| option == **s) {
Some(s) => result.push(format!("{s}=[REDACTED]")),
None => result.push(content),
}
result.push(if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&option) {
format!("{option}=[REDACTED]")
} else {
content
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ impl Span {
self.ctxt()
.outer_expn_data()
.allow_internal_unstable
.is_some_and(|features| features.iter().any(|&f| f == feature))
.is_some_and(|features| features.contains(&feature))
}

/// Checks if this span arises from a compiler desugaring of kind `kind`.
Expand Down
3 changes: 1 addition & 2 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,7 @@ impl Place {
/// In order to retrieve the correct type, the `locals` argument must match the list of all
/// locals from the function body where this place originates from.
pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error> {
let start_ty = locals[self.local].ty;
self.projection.iter().fold(Ok(start_ty), |place_ty, elem| elem.ty(place_ty?))
self.projection.iter().try_fold(locals[self.local].ty, |place_ty, elem| elem.ty(place_ty))
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub struct PlaceRef<'a> {
impl PlaceRef<'_> {
/// Get the type of this place.
pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error> {
self.projection.iter().fold(Ok(locals[self.local].ty), |place_ty, elem| elem.ty(place_ty?))
self.projection.iter().try_fold(locals[self.local].ty, |place_ty, elem| elem.ty(place_ty))
}
}

Expand Down
11 changes: 11 additions & 0 deletions library/coretests/tests/pin_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ fn temp_lifetime() {
}
async fn foo(_: &mut usize) {}
}

#[test]
fn transitive_extension() {
async fn temporary() {}

// `pin!` witnessed in the wild being used like this, even if it yields
// a `Pin<&mut &mut impl Unpin>`; it does work because `pin!`
// happens to transitively extend the lifespan of `temporary()`.
let p = pin!(&mut temporary());
let _use = p;
}
16 changes: 10 additions & 6 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ cfg_has_statx! {{
enum STATX_STATE{ Unknown = 0, Present, Unavailable }
static STATX_SAVED_STATE: AtomicU8 = AtomicU8::new(STATX_STATE::Unknown as u8);

syscall! {
syscall!(
fn statx(
fd: c_int,
pathname: *const c_char,
flags: c_int,
mask: libc::c_uint,
statxbuf: *mut libc::statx
) -> c_int
}
statxbuf: *mut libc::statx,
) -> c_int;
);

let statx_availability = STATX_SAVED_STATE.load(Ordering::Relaxed);
if statx_availability == STATX_STATE::Unavailable as u8 {
Expand Down Expand Up @@ -1540,7 +1540,9 @@ impl File {
let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?];
// futimens requires Android API level 19
cvt(unsafe {
weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
weak!(
fn futimens(fd: c_int, times: *const libc::timespec) -> c_int;
);
match futimens.get() {
Some(futimens) => futimens(self.as_raw_fd(), times.as_ptr()),
None => return Err(io::const_error!(
Expand All @@ -1556,7 +1558,9 @@ impl File {
use crate::sys::{time::__timespec64, weak::weak};

// Added in glibc 2.34
weak!(fn __futimens64(libc::c_int, *const __timespec64) -> libc::c_int);
weak!(
fn __futimens64(fd: c_int, times: *const __timespec64) -> c_int;
);

if let Some(futimens64) = __futimens64.get() {
let to_timespec = |time: Option<SystemTime>| time.map(|time| time.t.to_timespec64())
Expand Down
52 changes: 40 additions & 12 deletions library/std/src/sys/pal/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ impl FileDesc {
// implementation if `preadv` is not available.
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
super::weak::syscall! {
super::weak::syscall!(
fn preadv(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t
) -> isize
}
offset: off64_t,
) -> isize;
);

let ret = cvt(unsafe {
preadv(
Expand All @@ -257,7 +257,14 @@ impl FileDesc {
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
super::weak::weak!(fn preadv64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
super::weak::weak!(
fn preadv64(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t,
) -> isize;
);

match preadv64.get() {
Some(preadv) => {
Expand Down Expand Up @@ -286,7 +293,14 @@ impl FileDesc {
// use "weak" linking.
#[cfg(target_vendor = "apple")]
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
super::weak::weak!(fn preadv(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
super::weak::weak!(
fn preadv(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t,
) -> isize;
);

match preadv.get() {
Some(preadv) => {
Expand Down Expand Up @@ -428,14 +442,14 @@ impl FileDesc {
// implementation if `pwritev` is not available.
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
super::weak::syscall! {
super::weak::syscall!(
fn pwritev(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t
) -> isize
}
offset: off64_t,
) -> isize;
);

let ret = cvt(unsafe {
pwritev(
Expand All @@ -450,7 +464,14 @@ impl FileDesc {

#[cfg(all(target_os = "android", target_pointer_width = "32"))]
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
super::weak::weak!(fn pwritev64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
super::weak::weak!(
fn pwritev64(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t,
) -> isize;
);

match pwritev64.get() {
Some(pwritev) => {
Expand Down Expand Up @@ -479,7 +500,14 @@ impl FileDesc {
// use "weak" linking.
#[cfg(target_vendor = "apple")]
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
super::weak::weak!(fn pwritev(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
super::weak::weak!(
fn pwritev(
fd: libc::c_int,
iovec: *const libc::iovec,
n_iovec: libc::c_int,
offset: off64_t,
) -> isize;
);

match pwritev.get() {
Some(pwritev) => {
Expand Down
16 changes: 8 additions & 8 deletions library/std/src/sys/pal/unix/kernel_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,16 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) ->
_ => true,
};

syscall! {
syscall!(
fn copy_file_range(
fd_in: libc::c_int,
off_in: *mut libc::loff_t,
fd_out: libc::c_int,
off_out: *mut libc::loff_t,
len: libc::size_t,
flags: libc::c_uint
) -> libc::ssize_t
}
flags: libc::c_uint,
) -> libc::ssize_t;
);

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

#[cfg(target_os = "linux")]
use libc::splice;
Expand Down
30 changes: 22 additions & 8 deletions library/std/src/sys/pal/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,32 @@ mod imp {

let pages = PAGES.get_or_init(|| {
use crate::sys::weak::dlsym;
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);
dlsym!(
fn sysctlbyname(
name: *const libc::c_char,
oldp: *mut libc::c_void,
oldlenp: *mut libc::size_t,
newp: *const libc::c_void,
newlen: libc::size_t,
) -> libc::c_int;
);
let mut guard: usize = 0;
let mut size = size_of_val(&guard);
let oid = c"security.bsd.stack_guard_page";
match sysctlbyname.get() {
Some(fcn) if unsafe {
fcn(oid.as_ptr(),
(&raw mut guard).cast(),
&raw mut size,
ptr::null_mut(),
0) == 0
} => guard,
Some(fcn)
if unsafe {
fcn(
oid.as_ptr(),
(&raw mut guard).cast(),
&raw mut size,
ptr::null_mut(),
0,
) == 0
} =>
{
guard
}
_ => 1,
}
});
Expand Down
Loading
Loading