Skip to content
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

Rollup of 8 pull requests #139094

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
265ee9c
Start using with_native_path in std::sys::fs
ChrisDenton Mar 22, 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
fbe5e55
bootstrap: Avoid cloning change-id list
thaliaarchi Mar 28, 2025
4dfcd70
Rollup merge of #138692 - jieyouxu:reject-bool-lit-rev-names, r=wesle…
jhpratt Mar 29, 2025
2777f4a
Rollup merge of #138757 - rust-wasi-web:wasi-thread-stack-size, r=ale…
jhpratt Mar 29, 2025
429b676
Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboet
jhpratt Mar 29, 2025
9da804c
Rollup merge of #138988 - madsmtm:internal-weak-macro-syntax, r=ibrah…
jhpratt Mar 29, 2025
3d2282e
Rollup merge of #139044 - thaliaarchi:bootstrap-change-id-clone, r=on…
jhpratt Mar 29, 2025
66bdbde
Rollup merge of #139056 - yotamofek:pr/smir/try_fold, r=scottmcm
jhpratt Mar 29, 2025
fd9c468
Rollup merge of #139057 - yotamofek:pr/slice-contains, r=wesleywiser
jhpratt Mar 29, 2025
3b74a3e
Rollup merge of #139086 - meithecatte:expr-use-visitor-cleanup, r=com…
jhpratt 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
16 changes: 8 additions & 8 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ impl AsInner<fs_imp::DirEntry> for DirEntry {
#[doc(alias = "rm", alias = "unlink", alias = "DeleteFile")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
fs_imp::unlink(path.as_ref())
fs_imp::remove_file(path.as_ref())
}

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

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

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

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

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

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

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

impl DirBuilder {
Expand Down
99 changes: 92 additions & 7 deletions library/std/src/sys/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,113 @@
#![deny(unsafe_op_in_unsafe_fn)]

use crate::io;
use crate::path::{Path, PathBuf};

pub mod common;

cfg_if::cfg_if! {
if #[cfg(target_family = "unix")] {
mod unix;
pub use unix::*;
use unix as imp;
pub use unix::{chown, fchown, lchown, chroot};
pub(crate) use unix::debug_assert_fd_is_open;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) use unix::CachedFileMetadata;
use crate::sys::common::small_c_string::run_path_with_cstr as with_native_path;
} else if #[cfg(target_os = "windows")] {
mod windows;
pub use windows::*;
use windows as imp;
pub use windows::{symlink_inner, junction_point};
} else if #[cfg(target_os = "hermit")] {
mod hermit;
pub use hermit::*;
use hermit as imp;
} else if #[cfg(target_os = "solid_asp3")] {
mod solid;
pub use solid::*;
use solid as imp;
} else if #[cfg(target_os = "uefi")] {
mod uefi;
pub use uefi::*;
use uefi as imp;
} else if #[cfg(target_os = "wasi")] {
mod wasi;
pub use wasi::*;
use wasi as imp;
} else {
mod unsupported;
pub use unsupported::*;
use unsupported as imp;
}
}

// FIXME: Replace this with platform-specific path conversion functions.
#[cfg(not(target_family = "unix"))]
#[inline]
pub fn with_native_path<T>(path: &Path, f: &dyn Fn(&Path) -> io::Result<T>) -> io::Result<T> {
f(path)
}

pub use imp::{
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions,
ReadDir,
};

pub fn read_dir(path: &Path) -> io::Result<ReadDir> {
// FIXME: use with_native_path
imp::readdir(path)
}

pub fn remove_file(path: &Path) -> io::Result<()> {
with_native_path(path, &imp::unlink)
}

pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
with_native_path(old, &|old| with_native_path(new, &|new| imp::rename(old, new)))
}

pub fn remove_dir(path: &Path) -> io::Result<()> {
with_native_path(path, &imp::rmdir)
}

pub fn remove_dir_all(path: &Path) -> io::Result<()> {
// FIXME: use with_native_path
imp::remove_dir_all(path)
}

pub fn read_link(path: &Path) -> io::Result<PathBuf> {
with_native_path(path, &imp::readlink)
}

pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
with_native_path(original, &|original| {
with_native_path(link, &|link| imp::symlink(original, link))
})
}

pub fn hard_link(original: &Path, link: &Path) -> io::Result<()> {
with_native_path(original, &|original| {
with_native_path(link, &|link| imp::link(original, link))
})
}

pub fn metadata(path: &Path) -> io::Result<FileAttr> {
with_native_path(path, &imp::stat)
}

pub fn symlink_metadata(path: &Path) -> io::Result<FileAttr> {
with_native_path(path, &imp::lstat)
}

pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
with_native_path(path, &|path| imp::set_perm(path, perm.clone()))
}

pub fn canonicalize(path: &Path) -> io::Result<PathBuf> {
with_native_path(path, &imp::canonicalize)
}

pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
// FIXME: use with_native_path
imp::copy(from, to)
}

pub fn exists(path: &Path) -> io::Result<bool> {
// FIXME: use with_native_path
imp::exists(path)
}
Loading
Loading