From 314e224fa5cd0312975eaac809203baa108e743a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 10 Mar 2026 11:14:18 +1100 Subject: [PATCH 1/2] Streamline `find_dep_kind_root`. `current_id` is removable. --- compiler/rustc_query_impl/src/job.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index 64ed9b6b51bf2..bb906794bf233 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -88,6 +88,7 @@ pub(crate) fn find_cycle_in_stack<'tcx>( panic!("did not find a cycle") } +/// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id`. #[cold] #[inline(never)] pub(crate) fn find_dep_kind_root<'tcx>( @@ -95,18 +96,16 @@ pub(crate) fn find_dep_kind_root<'tcx>( job_map: QueryJobMap<'tcx>, ) -> (QueryJobInfo<'tcx>, usize) { let mut depth = 1; - let info = &job_map.map[&id]; + let mut info = &job_map.map[&id]; let dep_kind = info.frame.dep_kind; - let mut current_id = info.job.parent; let mut last_layout = (info.clone(), depth); - while let Some(id) = current_id { - let info = &job_map.map[&id]; + while let Some(id) = info.job.parent { + info = &job_map.map[&id]; if info.frame.dep_kind == dep_kind { depth += 1; last_layout = (info.clone(), depth); } - current_id = info.job.parent; } last_layout } From ddd1a69483c9a5503b5f2e0b563d9b015f164b86 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 10 Mar 2026 14:00:45 +1100 Subject: [PATCH 2/2] Remove `Clone` derive on `QueryJobInfo`. This requires refactoring `depth_limit_error` to do some extra work immediately instead of returning a cloned `info`. --- compiler/rustc_query_impl/src/job.rs | 14 ++++++++------ compiler/rustc_query_impl/src/plumbing.rs | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index bb906794bf233..67995ccfc490a 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -46,7 +46,7 @@ impl<'tcx> QueryJobMap<'tcx> { } } -#[derive(Clone, Debug)] +#[derive(Debug)] pub(crate) struct QueryJobInfo<'tcx> { pub(crate) frame: QueryStackFrame<'tcx>, pub(crate) job: QueryJob<'tcx>, @@ -88,26 +88,28 @@ pub(crate) fn find_cycle_in_stack<'tcx>( panic!("did not find a cycle") } -/// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id`. +/// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id` and returns +/// information about it. #[cold] #[inline(never)] pub(crate) fn find_dep_kind_root<'tcx>( + tcx: TyCtxt<'tcx>, id: QueryJobId, job_map: QueryJobMap<'tcx>, -) -> (QueryJobInfo<'tcx>, usize) { +) -> (Span, String, usize) { let mut depth = 1; let mut info = &job_map.map[&id]; let dep_kind = info.frame.dep_kind; - let mut last_layout = (info.clone(), depth); + let mut last_info = info; while let Some(id) = info.job.parent { info = &job_map.map[&id]; if info.frame.dep_kind == dep_kind { depth += 1; - last_layout = (info.clone(), depth); + last_info = info; } } - last_layout + (last_info.job.span, last_info.frame.tagged_key.description(tcx), depth) } /// A resumable waiter of a query. The usize is the index into waiters in the query's latch diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index bece2e56c0a86..66c62d6125b16 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -36,16 +36,16 @@ use crate::{ fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) { let job_map = collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::Full); - let (info, depth) = find_dep_kind_root(job, job_map); + let (span, desc, depth) = find_dep_kind_root(tcx, job, job_map); let suggested_limit = match tcx.recursion_limit() { Limit(0) => Limit(2), limit => limit * 2, }; - tcx.sess.dcx().emit_fatal(QueryOverflow { - span: info.job.span, - note: QueryOverflowNote { desc: info.frame.tagged_key.description(tcx), depth }, + tcx.dcx().emit_fatal(QueryOverflow { + span, + note: QueryOverflowNote { desc, depth }, suggested_limit, crate_name: tcx.crate_name(LOCAL_CRATE), });