Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0bb020a
Make `const_lit_matches_ty` check literal suffixes for exact type match
lapla-cogito Feb 22, 2026
7b4474a
Remove `TaskDeps::phantom_data`.
nnethercote Mar 2, 2026
69042d1
Remove unused `Lift` impl.
nnethercote Mar 2, 2026
b3fddcb
Add a comment explaining the 'tcx lifetime.
nnethercote Mar 4, 2026
e26974c
bootstrap: minimal fix for ./x install src with build.docs = false
alistair23 Jan 8, 2026
169dd72
Fix obtaining def_id from unresolved segment
aerooneqq Mar 5, 2026
1f1a0bc
constify Vec::{into, from}_raw_parts{_in|_alloc}
bend-n Mar 5, 2026
f352e74
Use shlex instead of shell-words
eggyal Mar 5, 2026
743d442
Rename `QueryCache::iter` to `for_each`
Zalathar Mar 4, 2026
072bd69
Fix ICEs due to incomplete typechecking on struct literals with synta…
kpreid Mar 5, 2026
082d0ca
Rollup merge of #153399 - bend-n:constify-into-raw-parts, r=Amanieu
JonathanBrouwer Mar 5, 2026
77f0241
Rollup merge of #153436 - eggyal:shlex-not-shell_words, r=ChrisDenton
JonathanBrouwer Mar 5, 2026
6d7b282
Rollup merge of #150845 - alistair23:alistair/doc-build-fixup, r=jiey…
JonathanBrouwer Mar 5, 2026
9632fd8
Rollup merge of #152906 - lapla-cogito:issue_152653, r=BoxyUwU
JonathanBrouwer Mar 5, 2026
31c5680
Rollup merge of #153378 - Zalathar:for-each, r=fee1-dead
JonathanBrouwer Mar 5, 2026
1e70647
Rollup merge of #153386 - nnethercote:minor-query-cleanups, r=petroch…
JonathanBrouwer Mar 5, 2026
e26f208
Rollup merge of #153422 - nnethercote:tcx-comment, r=bjorn3
JonathanBrouwer Mar 5, 2026
4a5a216
Rollup merge of #153435 - aerooneqq:delegation_res_def_id_ice, r=petr…
JonathanBrouwer Mar 5, 2026
11c4bea
Rollup merge of #153453 - kpreid:fix-153388, r=fmease,estebank
JonathanBrouwer Mar 5, 2026
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
8 changes: 1 addition & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4121,7 +4121,7 @@ version = "0.0.0"
dependencies = [
"cc",
"libc",
"shell-words",
"shlex",
]

[[package]]
Expand Down Expand Up @@ -5116,12 +5116,6 @@ dependencies = [
"lazy_static",
]

[[package]]
name = "shell-words"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"

[[package]]
name = "shlex"
version = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/vec_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ where
}
}

pub fn iter(&self, f: &mut dyn FnMut(&K, &V, I)) {
pub fn for_each(&self, f: &mut dyn FnMut(&K, &V, I)) {
for idx in 0..self.len.load(Ordering::Acquire) {
let key = SlotIndex::from_index(idx as u32);
match unsafe { key.get(&self.present) } {
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,15 @@ fn get_delegation_user_specified_args<'tcx>(
.opt_delegation_generics()
.expect("Lowering delegation");

let get_segment = |hir_id: HirId| -> (&'tcx PathSegment<'tcx>, DefId) {
let get_segment = |hir_id: HirId| -> Option<(&'tcx PathSegment<'tcx>, DefId)> {
let segment = tcx.hir_node(hir_id).expect_path_segment();
let def_id = segment.res.def_id();

(segment, def_id)
segment.res.opt_def_id().map(|def_id| (segment, def_id))
};

let ctx = ItemCtxt::new(tcx, delegation_id);
let lowerer = ctx.lowerer();

let parent_args = info.parent_args_segment_id.map(get_segment).map(|(segment, def_id)| {
let parent_args = info.parent_args_segment_id.and_then(get_segment).map(|(segment, def_id)| {
let self_ty = get_delegation_self_ty(tcx, delegation_id);

lowerer
Expand All @@ -598,7 +596,7 @@ fn get_delegation_user_specified_args<'tcx>(
.as_slice()
});

let child_args = info.child_args_segment_id.map(get_segment).map(|(segment, def_id)| {
let child_args = info.child_args_segment_id.and_then(get_segment).map(|(segment, def_id)| {
let parent_args = if let Some(parent_args) = parent_args {
parent_args
} else {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,14 +2203,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
self.typeck_results.borrow_mut().fru_field_types_mut().insert(expr.hir_id, fru_tys);
}
rustc_hir::StructTailExpr::NoneWithError(ErrorGuaranteed { .. }) => {
rustc_hir::StructTailExpr::NoneWithError(guaranteed) => {
// If parsing the struct recovered from a syntax error, do not report missing
// fields. This prevents spurious errors when a field is intended to be present
// but a preceding syntax error caused it not to be parsed. For example, if a
// struct type `StructName` has fields `foo` and `bar`, then
// StructName { foo(), bar: 2 }
// will not successfully parse a field `foo`, but we will not mention that,
// since the syntax error has already been reported.

// Signal that type checking has failed, even though we haven’t emitted a diagnostic
// about it ourselves.
self.infcx.set_tainted_by_errors(guaranteed);
}
rustc_hir::StructTailExpr::None => {
if adt_kind != AdtKind::Union
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,17 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(

let incremental = dep_graph.is_fully_enabled();

// Note: this function body is the origin point of the widely-used 'tcx lifetime.
//
// `gcx_cell` is defined here and `&gcx_cell` is passed to `create_global_ctxt`, which then
// actually creates the `GlobalCtxt` with a `gcx_cell.get_or_init(...)` call. This is done so
// that the resulting reference has the type `&'tcx GlobalCtxt<'tcx>`, which is what `TyCtxt`
// needs. If we defined and created the `GlobalCtxt` within `create_global_ctxt` then its type
// would be `&'a GlobalCtxt<'tcx>`, with two lifetimes.
//
// Similarly, by creating `arena` here and passing in `&arena`, that reference has the type
// `&'tcx WorkerLocal<Arena<'tcx>>`, also with one lifetime. And likewise for `hir_arena`.

let gcx_cell = OnceLock::new();
let arena = WorkerLocal::new(|_| Arena::default());
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ libc = "0.2.73"
# tidy-alphabetical-start
# `cc` updates often break things, so we pin it here.
cc = "=1.2.16"
shell-words = "1.1.1"
shlex = "1.3.0"
# tidy-alphabetical-end

[features]
Expand Down
32 changes: 21 additions & 11 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::process::{Command, Output, Stdio};
use std::str::SplitWhitespace;
use std::vec::IntoIter;

use shlex::Shlex;

const OPTIONAL_COMPONENTS: &[&str] = &[
"x86",
Expand Down Expand Up @@ -121,9 +122,8 @@ enum LlvmConfigOutput {
UnquotedPaths(String),
}

#[derive(Clone)]
enum SplitLlvmConfigOutput<'a> {
QuotedPaths(IntoIter<String>),
QuotedPaths(Shlex<'a>),
UnquotedPaths(SplitWhitespace<'a>),
}

Expand All @@ -137,14 +137,22 @@ impl<'a> Iterator for SplitLlvmConfigOutput<'a> {
}
}

impl Drop for SplitLlvmConfigOutput<'_> {
fn drop(&mut self) {
if let Self::QuotedPaths(shlex) = self {
assert!(!shlex.had_error, "error parsing llvm-config output");
}
}
}

impl<'a> IntoIterator for &'a LlvmConfigOutput {
type Item = Cow<'a, str>;
type IntoIter = SplitLlvmConfigOutput<'a>;
fn into_iter(self) -> Self::IntoIter {
match self {
LlvmConfigOutput::QuotedPaths(output) => SplitLlvmConfigOutput::QuotedPaths(
shell_words::split(&output).expect("matched quotes").into_iter(),
),
LlvmConfigOutput::QuotedPaths(output) => {
SplitLlvmConfigOutput::QuotedPaths(Shlex::new(output))
}
LlvmConfigOutput::UnquotedPaths(output) => {
SplitLlvmConfigOutput::UnquotedPaths(output.split_whitespace())
}
Expand Down Expand Up @@ -229,7 +237,6 @@ fn main() {
let mut cmd = Command::new(&llvm_config);
cmd.arg("--cxxflags");
let cxxflags = quoted_split(cmd);
let mut cxxflags_iter = cxxflags.into_iter();
let mut cfg = cc::Build::new();
cfg.warnings(false);

Expand All @@ -242,7 +249,7 @@ fn main() {
if std::env::var_os("CI").is_some() && !target.contains("msvc") {
cfg.warnings_into_errors(true);
}
for flag in cxxflags_iter.clone() {
for flag in &cxxflags {
// Ignore flags like `-m64` when we're doing a cross build
if is_crossed && flag.starts_with("-m") {
continue;
Expand Down Expand Up @@ -435,13 +442,16 @@ fn main() {
// dependencies.
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
if let Some(s) = llvm_linker_flags {
for lib in shell_words::split(&s.into_string().unwrap()).expect("matched quotes") {
let linker_flags = s.into_string().unwrap();
let mut shlex = Shlex::new(&linker_flags);
for lib in shlex.by_ref() {
if let Some(stripped) = lib.strip_prefix("-l") {
println!("cargo:rustc-link-lib={stripped}");
} else if let Some(stripped) = lib.strip_prefix("-L") {
println!("cargo:rustc-link-search=native={stripped}");
}
}
assert!(!shlex.had_error, "error parsing LLVM_LINKER_FLAGS");
}

let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
Expand Down Expand Up @@ -476,15 +486,15 @@ fn main() {
// C++ runtime library
if !target.contains("msvc") {
if let Some(s) = llvm_static_stdcpp {
assert!(cxxflags_iter.all(|flag| flag != "-stdlib=libc++"));
assert!(cxxflags.into_iter().all(|flag| flag != "-stdlib=libc++"));
let path = PathBuf::from(s);
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
if target.contains("windows") {
println!("cargo:rustc-link-lib=static:-bundle={stdcppname}");
} else {
println!("cargo:rustc-link-lib=static={stdcppname}");
}
} else if cxxflags_iter.any(|flag| flag == "-stdlib=libc++") {
} else if cxxflags.into_iter().any(|flag| flag == "-stdlib=libc++") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib={stdcppname}");
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};

Expand Down Expand Up @@ -1377,8 +1376,6 @@ pub struct TaskDeps {
/// scan. If the number is higher, a hashset has better perf. This field is that hashset. It's
/// only used if the number of elements in `reads` exceeds `LINEAR_SCAN_MAX`.
read_set: FxHashSet<DepNodeIndex>,

phantom_data: PhantomData<DepNode>,
}

impl TaskDeps {
Expand All @@ -1392,7 +1389,6 @@ impl TaskDeps {
node,
reads: EdgesVec::new(),
read_set: FxHashSet::with_capacity_and_hasher(read_set_capacity, Default::default()),
phantom_data: PhantomData,
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions compiler/rustc_middle/src/query/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ pub trait QueryCache: Sized {
/// value by executing the query or loading a cached value from disk.
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
/// Calls a closure on each entry in this cache.
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));

/// Returns the number of entries currently in this cache.
///
/// Useful for reserving capacity in data structures that will hold the
/// output of a call to [`Self::for_each`].
fn len(&self) -> usize;
}

Expand Down Expand Up @@ -65,7 +70,7 @@ where
self.cache.insert(key, (value, index));
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
for shard in self.cache.lock_shards() {
for (k, v) in shard.iter() {
f(k, &v.0, v.1);
Expand Down Expand Up @@ -107,7 +112,7 @@ where
self.cache.set((value, index)).ok();
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
if let Some(value) = self.cache.get() {
f(&(), &value.0, value.1)
}
Expand Down Expand Up @@ -160,11 +165,11 @@ where
}
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.local.iter(&mut |key, value, index| {
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.local.for_each(&mut |key, value, index| {
f(&DefId { krate: LOCAL_CRATE, index: *key }, value, index);
});
self.foreign.iter(f);
self.foreign.for_each(f);
}

fn len(&self) -> usize {
Expand All @@ -190,8 +195,8 @@ where
self.complete(key, value, index)
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.iter(f)
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
self.for_each(f)
}

fn len(&self) -> usize {
Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_middle/src/ty/consts/lit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_ast::LitKind;
use rustc_ast::{LitFloatType, LitIntType, LitKind};
use rustc_hir;
use rustc_macros::HashStable;

Expand Down Expand Up @@ -44,10 +44,17 @@ pub fn const_lit_matches_ty<'tcx>(
{
true
}
(LitKind::Int(..), ty::Uint(_)) if !neg => true,
(LitKind::Int(..), ty::Int(_)) => true,
(LitKind::Int(_, LitIntType::Unsigned(lit_ty)), ty::Uint(expect_ty)) if !neg => {
lit_ty == *expect_ty
}
(LitKind::Int(_, LitIntType::Signed(lit_ty)), ty::Int(expect_ty)) => lit_ty == *expect_ty,
(LitKind::Int(_, LitIntType::Unsuffixed), ty::Uint(_)) if !neg => true,
(LitKind::Int(_, LitIntType::Unsuffixed), ty::Int(_)) => true,
(LitKind::Bool(..), ty::Bool) => true,
(LitKind::Float(..), ty::Float(_)) => true,
(LitKind::Float(_, LitFloatType::Suffixed(lit_ty)), ty::Float(expect_ty)) => {
lit_ty == *expect_ty
}
(LitKind::Float(_, LitFloatType::Unsuffixed), ty::Float(_)) => true,
(LitKind::Char(..), ty::Char) => true,
(LitKind::Err(..), _) => true,
_ => false,
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! to help with the tedium.
use std::fmt::{self, Debug};
use std::marker::PhantomData;

use rustc_abi::TyAndLayout;
use rustc_hir::def::Namespace;
Expand Down Expand Up @@ -270,13 +269,6 @@ TrivialTypeTraversalAndLiftImpls! {
///////////////////////////////////////////////////////////////////////////
// Lift implementations

impl<'tcx> Lift<TyCtxt<'tcx>> for PhantomData<&()> {
type Lifted = PhantomData<&'tcx ()>;
fn lift_to_interner(self, _: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some(PhantomData)
}
}

impl<'tcx, T: Lift<TyCtxt<'tcx>>> Lift<TyCtxt<'tcx>> for Option<T> {
type Lifted = Option<T::Lifted>;
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, C, V>(
let _timer = tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name);

assert!(all_inactive(&query.state));
query.cache.iter(&mut |key, value, dep_node| {
query.cache.for_each(&mut |key, value, dep_node| {
if (query.will_cache_on_disk_for_key_fn)(tcx, key) {
let dep_node = SerializedDepNodeIndex::new(dep_node.index());

Expand All @@ -189,7 +189,7 @@ pub(crate) fn query_key_hash_verify<'tcx, C: QueryCache>(

let cache = &query.cache;
let mut map = UnordMap::with_capacity(cache.len());
cache.iter(&mut |key, _, _| {
cache.for_each(&mut |key, _, _| {
let node = DepNode::construct(tcx, query.dep_kind, key);
if let Some(other_key) = map.insert(node, *key) {
bug!(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/profiling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
// locked while doing so. Instead we copy out the
// `(query_key, dep_node_index)` pairs and release the lock again.
let mut query_keys_and_indices = Vec::new();
query_cache.iter(&mut |k, _, i| query_keys_and_indices.push((*k, i)));
query_cache.for_each(&mut |k, _, i| query_keys_and_indices.push((*k, i)));

// Now actually allocate the strings. If allocating the strings
// generates new entries in the query cache, we'll miss them but
Expand Down Expand Up @@ -228,7 +228,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
// instead of passing the `DepNodeIndex` to `finish_with_query_invocation_id`,
// when recording the event in the first place.
let mut query_invocation_ids = Vec::new();
query_cache.iter(&mut |_, _, i| {
query_cache.for_each(&mut |_, _, i| {
query_invocation_ids.push(i.into());
});

Expand Down
Loading
Loading