Skip to content

Commit dbb7cad

Browse files
committed
Auto merge of #153714 - JonathanBrouwer:rollup-TbcSvLX, r=<try>
Rollup of 4 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents a63150b + 3d58edc commit dbb7cad

25 files changed

Lines changed: 260 additions & 257 deletions

File tree

compiler/rustc_errors/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,6 @@ pub enum StashKey {
371371
MaybeFruTypo,
372372
CallAssocMethod,
373373
AssociatedTypeSuggestion,
374-
/// Query cycle detected, stashing in favor of a better error.
375-
Cycle,
376374
UndeterminedMacroResolution,
377375
/// Used by `Parser::maybe_recover_trailing_expr`
378376
ExprInPat,

compiler/rustc_hir_analysis/src/check/compare_eii.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::iter;
99
use rustc_data_structures::fx::FxIndexSet;
1010
use rustc_errors::{Applicability, E0806, struct_span_code_err};
1111
use rustc_hir::attrs::EiiImplResolution;
12+
use rustc_hir::def::DefKind;
1213
use rustc_hir::def_id::{DefId, LocalDefId};
1314
use rustc_hir::{self as hir, FnSig, HirId, ItemKind, find_attr};
1415
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
@@ -37,6 +38,14 @@ pub(crate) fn compare_eii_function_types<'tcx>(
3738
eii_name: Symbol,
3839
eii_attr_span: Span,
3940
) -> Result<(), ErrorGuaranteed> {
41+
// Error recovery can resolve the EII target to another value item with the same name,
42+
// such as a tuple-struct constructor. Skip the comparison in that case and rely on the
43+
// earlier name-resolution error instead of ICEing while building EII diagnostics.
44+
// See <https://github.com/rust-lang/rust/issues/153502>.
45+
if !is_foreign_function(tcx, foreign_item) {
46+
return Ok(());
47+
}
48+
4049
check_is_structurally_compatible(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;
4150

4251
let external_impl_span = tcx.def_span(external_impl);
@@ -442,3 +451,7 @@ fn get_declaration_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Option<&'
442451
let hir_id: HirId = tcx.local_def_id_to_hir_id(def_id);
443452
tcx.hir_fn_sig_by_hir_id(hir_id)
444453
}
454+
455+
fn is_foreign_function(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
456+
tcx.is_foreign_item(def_id) && matches!(tcx.def_kind(def_id), DefKind::Fn)
457+
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_errors::{Applicability, StashKey, Suggestions};
44
use rustc_hir::def_id::{DefId, LocalDefId};
55
use rustc_hir::intravisit::VisitorExt;
66
use rustc_hir::{self as hir, AmbigArg, HirId};
7-
use rustc_middle::query::plumbing::CyclePlaceholder;
87
use rustc_middle::ty::print::with_forced_trimmed_paths;
98
use rustc_middle::ty::util::IntTypeExt;
109
use rustc_middle::ty::{self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
@@ -183,10 +182,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
183182
}
184183
},
185184

186-
Node::OpaqueTy(..) => tcx.type_of_opaque(def_id).map_or_else(
187-
|CyclePlaceholder(guar)| Ty::new_error(tcx, guar),
188-
|ty| ty.instantiate_identity(),
189-
),
185+
Node::OpaqueTy(..) => tcx.type_of_opaque(def_id).instantiate_identity(),
190186

191187
Node::ForeignItem(foreign_item) => match foreign_item.kind {
192188
ForeignItemKind::Fn(..) => {
@@ -249,12 +245,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
249245
}
250246
}
251247

252-
pub(super) fn type_of_opaque(
253-
tcx: TyCtxt<'_>,
254-
def_id: DefId,
255-
) -> Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
248+
pub(super) fn type_of_opaque(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_, Ty<'_>> {
256249
if let Some(def_id) = def_id.as_local() {
257-
Ok(match tcx.hir_node_by_def_id(def_id).expect_opaque_ty().origin {
250+
match tcx.hir_node_by_def_id(def_id).expect_opaque_ty().origin {
258251
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => {
259252
opaque::find_opaque_ty_constraints_for_tait(
260253
tcx,
@@ -287,11 +280,11 @@ pub(super) fn type_of_opaque(
287280
DefiningScopeKind::MirBorrowck,
288281
)
289282
}
290-
})
283+
}
291284
} else {
292285
// Foreign opaque type will go through the foreign provider
293286
// and load the type from metadata.
294-
Ok(tcx.type_of(def_id))
287+
tcx.type_of(def_id)
295288
}
296289
}
297290

compiler/rustc_macros/src/query.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ struct QueryModifiers {
144144
arena_cache: Option<Ident>,
145145
cache_on_disk_if: Option<CacheOnDiskIf>,
146146
cycle_delay_bug: Option<Ident>,
147-
cycle_stash: Option<Ident>,
148147
depth_limit: Option<Ident>,
149148
desc: Desc,
150149
eval_always: Option<Ident>,
@@ -159,7 +158,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
159158
let mut cache_on_disk_if = None;
160159
let mut desc = None;
161160
let mut cycle_delay_bug = None;
162-
let mut cycle_stash = None;
163161
let mut no_hash = None;
164162
let mut anon = None;
165163
let mut eval_always = None;
@@ -195,8 +193,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
195193
try_insert!(arena_cache = modifier);
196194
} else if modifier == "cycle_delay_bug" {
197195
try_insert!(cycle_delay_bug = modifier);
198-
} else if modifier == "cycle_stash" {
199-
try_insert!(cycle_stash = modifier);
200196
} else if modifier == "no_hash" {
201197
try_insert!(no_hash = modifier);
202198
} else if modifier == "anon" {
@@ -221,7 +217,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
221217
cache_on_disk_if,
222218
desc,
223219
cycle_delay_bug,
224-
cycle_stash,
225220
no_hash,
226221
anon,
227222
eval_always,
@@ -257,7 +252,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
257252
arena_cache,
258253
cache_on_disk_if,
259254
cycle_delay_bug,
260-
cycle_stash,
261255
depth_limit,
262256
desc: _,
263257
eval_always,
@@ -273,8 +267,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
273267

274268
let cycle_error_handling = if cycle_delay_bug.is_some() {
275269
quote! { DelayBug }
276-
} else if cycle_stash.is_some() {
277-
quote! { Stash }
278270
} else {
279271
quote! { Error }
280272
};
@@ -411,7 +403,6 @@ fn add_to_analyzer_stream(query: &Query, analyzer_stream: &mut proc_macro2::Toke
411403
doc_link!(
412404
arena_cache,
413405
cycle_delay_bug,
414-
cycle_stash,
415406
no_hash,
416407
anon,
417408
eval_always,

compiler/rustc_middle/src/queries.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
//! - `cache_on_disk_if { ... }`: Cache the query result to disk if the provided block evaluates to
3434
//! true. The query key identifier is available for use within the block, as is `tcx`.
3535
//! - `cycle_delay_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
36-
//! - `cycle_stash`: If a dependency cycle is detected, stash the error for later handling.
3736
//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
3837
//! - `anon`: Make the query anonymous in the dependency graph (no dep node is created).
3938
//! - `eval_always`: Always evaluate the query, ignoring its dependencies and cached results.
@@ -118,7 +117,6 @@ use crate::mir::mono::{
118117
CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions, NormalizationErrorInMono,
119118
};
120119
use crate::query::describe_as_module;
121-
use crate::query::plumbing::CyclePlaceholder;
122120
use crate::traits::query::{
123121
CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
124122
CanonicalMethodAutoderefStepsGoal, CanonicalPredicateGoal, CanonicalTypeOpAscribeUserTypeGoal,
@@ -339,22 +337,16 @@ rustc_queries! {
339337
feedable
340338
}
341339

342-
/// Returns the *hidden type* of the opaque type given by `DefId` unless a cycle occurred.
343-
///
344-
/// This is a specialized instance of [`Self::type_of`] that detects query cycles.
345-
/// Unless `CyclePlaceholder` needs to be handled separately, call [`Self::type_of`] instead.
346-
/// This is used to improve the error message in cases where revealing the hidden type
347-
/// for auto-trait leakage cycles.
340+
/// Returns the *hidden type* of the opaque type given by `DefId`.
348341
///
349342
/// # Panics
350343
///
351344
/// This query will panic if the given definition is not an opaque type.
352-
query type_of_opaque(key: DefId) -> Result<ty::EarlyBinder<'tcx, Ty<'tcx>>, CyclePlaceholder> {
345+
query type_of_opaque(key: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
353346
desc {
354347
"computing type of opaque `{path}`",
355348
path = tcx.def_path_str(key),
356349
}
357-
cycle_stash
358350
}
359351
query type_of_opaque_hir_typeck(key: LocalDefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
360352
desc {

compiler/rustc_middle/src/query/erase.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_span::{ErrorGuaranteed, Spanned};
1414

1515
use crate::mir::interpret::EvalToValTreeResult;
1616
use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
17-
use crate::query::plumbing::CyclePlaceholder;
1817
use crate::traits::solve;
1918
use crate::ty::adjustment::CoerceUnsizedInfo;
2019
use crate::ty::{self, Ty, TyCtxt};
@@ -212,10 +211,6 @@ impl Erasable for Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop> {
212211
[u8; size_of::<Result<&'static ty::List<Ty<'static>>, ty::util::AlwaysRequiresDrop>>()];
213212
}
214213

215-
impl Erasable for Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
216-
type Storage = [u8; size_of::<Result<ty::EarlyBinder<'static, Ty<'_>>, CyclePlaceholder>>()];
217-
}
218-
219214
impl Erasable
220215
for Result<(&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]), NormalizationErrorInMono>
221216
{

compiler/rustc_middle/src/query/modifiers.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ pub(crate) struct cache_on_disk_if;
2828
/// A cycle error results in a delay_bug call
2929
pub(crate) struct cycle_delay_bug;
3030

31-
/// # `cycle_stash` query modifier
32-
///
33-
/// A cycle error results in a stashed cycle error that can be unstashed and canceled later
34-
pub(crate) struct cycle_stash;
35-
3631
/// # `depth_limit` query modifier
3732
///
3833
/// Whether the query has a call depth limit

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::sharded::Sharded;
77
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::hir_id::OwnerId;
10-
use rustc_macros::HashStable;
1110
use rustc_span::{ErrorGuaranteed, Span};
1211
pub use sealed::IntoQueryParam;
1312

@@ -58,7 +57,6 @@ pub enum ActiveKeyStatus<'tcx> {
5857
pub enum CycleErrorHandling {
5958
Error,
6059
DelayBug,
61-
Stash,
6260
}
6361

6462
#[derive(Clone, Debug)]
@@ -651,9 +649,6 @@ mod sealed {
651649
}
652650
}
653651

654-
#[derive(Copy, Clone, Debug, HashStable)]
655-
pub struct CyclePlaceholder(pub ErrorGuaranteed);
656-
657652
#[cold]
658653
pub(crate) fn default_query(name: &str, key: &dyn std::fmt::Debug) -> ! {
659654
bug!(

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,6 @@ pub enum SelectionError<'tcx> {
633633
NotConstEvaluatable(NotConstEvaluatable),
634634
/// Exceeded the recursion depth during type projection.
635635
Overflow(OverflowError),
636-
/// Computing an opaque type's hidden type caused an error (e.g. a cycle error).
637-
/// We can thus not know whether the hidden type implements an auto trait, so
638-
/// we should not presume anything about it.
639-
OpaqueTypeAutoTraitLeakageUnknown(DefId),
640636
/// Error for a `ConstArgHasType` goal
641637
ConstArgHasWrongType { ct: ty::Const<'tcx>, ct_ty: Ty<'tcx>, expected_ty: Ty<'tcx> },
642638
}

compiler/rustc_query_impl/src/execution.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::hash_table::{Entry, HashTable};
55
use rustc_data_structures::stack::ensure_sufficient_stack;
66
use rustc_data_structures::sync::{DynSend, DynSync};
77
use rustc_data_structures::{outline, sharded, sync};
8-
use rustc_errors::{FatalError, StashKey};
8+
use rustc_errors::FatalError;
99
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
1010
use rustc_middle::query::plumbing::QueryVTable;
1111
use rustc_middle::query::{
@@ -16,8 +16,8 @@ use rustc_middle::ty::TyCtxt;
1616
use rustc_middle::verify_ich::incremental_verify_ich;
1717
use rustc_span::{DUMMY_SP, Span};
1818

19-
use crate::collect_active_jobs_from_all_queries;
2019
use crate::dep_graph::{DepNode, DepNodeIndex};
20+
use crate::for_each_query_vtable;
2121
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
2222
use crate::plumbing::{current_query_job, next_job_id, start_query};
2323

@@ -30,14 +30,41 @@ pub(crate) fn all_inactive<'tcx, K>(state: &QueryState<'tcx, K>) -> bool {
3030
state.active.lock_shards().all(|shard| shard.is_empty())
3131
}
3232

33+
/// Returns a map of currently active query jobs, collected from all queries.
34+
///
35+
/// If `require_complete` is `true`, this function locks all shards of the
36+
/// query results to produce a complete map, which always returns `Ok`.
37+
/// Otherwise, it may return an incomplete map as an error if any shard
38+
/// lock cannot be acquired.
39+
///
40+
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
41+
/// especially when called from within a deadlock handler, unless a
42+
/// complete map is needed and no deadlock is possible at this call site.
43+
pub fn collect_active_jobs_from_all_queries<'tcx>(
44+
tcx: TyCtxt<'tcx>,
45+
require_complete: bool,
46+
) -> Result<QueryJobMap<'tcx>, QueryJobMap<'tcx>> {
47+
let mut job_map_out = QueryJobMap::default();
48+
let mut complete = true;
49+
50+
for_each_query_vtable!(ALL, tcx, |query| {
51+
let res = gather_active_jobs(query, tcx, require_complete, &mut job_map_out);
52+
if res.is_none() {
53+
complete = false;
54+
}
55+
});
56+
57+
if complete { Ok(job_map_out) } else { Err(job_map_out) }
58+
}
59+
3360
/// Internal plumbing for collecting the set of active jobs for this query.
3461
///
3562
/// Should only be called from `collect_active_jobs_from_all_queries`.
3663
///
3764
/// (We arbitrarily use the word "gather" when collecting the jobs for
3865
/// each individual query, so that we have distinct function names to
3966
/// grep for.)
40-
pub(crate) fn gather_active_jobs<'tcx, C>(
67+
fn gather_active_jobs<'tcx, C>(
4168
query: &'tcx QueryVTable<'tcx, C>,
4269
tcx: TyCtxt<'tcx>,
4370
require_complete: bool,
@@ -110,16 +137,6 @@ fn mk_cycle<'tcx, C: QueryCache>(
110137
let guar = error.delay_as_bug();
111138
(query.value_from_cycle_error)(tcx, cycle_error, guar)
112139
}
113-
CycleErrorHandling::Stash => {
114-
let guar = if let Some(root) = cycle_error.cycle.first()
115-
&& let Some(span) = root.frame.info.span
116-
{
117-
error.stash(span, StashKey::Cycle).unwrap()
118-
} else {
119-
error.emit()
120-
};
121-
(query.value_from_cycle_error)(tcx, cycle_error, guar)
122-
}
123140
}
124141
}
125142

0 commit comments

Comments
 (0)