From 0932068b6c9330f54eab92d5888131e6c877b3ce Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 2 Feb 2026 16:05:26 +1100 Subject: [PATCH] Move the `QueryOverflow` and `QueryOverflowNote` errors. They are defined in `rustc_query_system` but used in `rustc_query_impl`. This is very much *not* how things are supposed to be done; I suspect someone got lazy and took a shortcut at some point. This commit moves the errors into `rustc_query_impl`. This requires more lines of code to give `rustc_query_impl` an errors module, but it's worthwhile to do things in the normal way instead of a weird exceptional way. --- Cargo.lock | 2 ++ compiler/rustc_query_impl/Cargo.toml | 2 ++ compiler/rustc_query_impl/src/error.rs | 24 +++++++++++++++++++++++ compiler/rustc_query_impl/src/lib.rs | 2 ++ compiler/rustc_query_impl/src/plumbing.rs | 2 +- compiler/rustc_query_system/src/error.rs | 24 +---------------------- compiler/rustc_query_system/src/lib.rs | 2 -- 7 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 compiler/rustc_query_impl/src/error.rs diff --git a/Cargo.lock b/Cargo.lock index 85d3fc1aa7bf..363cb8a5dc05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4534,9 +4534,11 @@ version = "0.0.0" dependencies = [ "measureme", "rustc_data_structures", + "rustc_errors", "rustc_hashes", "rustc_hir", "rustc_index", + "rustc_macros", "rustc_middle", "rustc_query_system", "rustc_serialize", diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index 257785b10c8b..d611629671a0 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -7,9 +7,11 @@ edition = "2024" # tidy-alphabetical-start measureme = "12.0.1" rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } +rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_query_system = { path = "../rustc_query_system" } rustc_serialize = { path = "../rustc_serialize" } diff --git a/compiler/rustc_query_impl/src/error.rs b/compiler/rustc_query_impl/src/error.rs new file mode 100644 index 000000000000..b109172d8e49 --- /dev/null +++ b/compiler/rustc_query_impl/src/error.rs @@ -0,0 +1,24 @@ +use rustc_hir::limit::Limit; +use rustc_macros::{Diagnostic, Subdiagnostic}; +use rustc_span::{Span, Symbol}; + +#[derive(Diagnostic)] +#[help( + "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)" +)] +#[diag("queries overflow the depth limit!")] +pub(crate) struct QueryOverflow { + #[primary_span] + pub span: Span, + #[subdiagnostic] + pub note: QueryOverflowNote, + pub suggested_limit: Limit, + pub crate_name: Symbol, +} + +#[derive(Subdiagnostic)] +#[note("query depth increased by {$depth} when {$desc}")] +pub(crate) struct QueryOverflowNote { + pub desc: String, + pub depth: usize, +} diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 6c9a075177ad..cb5010861e5f 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -39,6 +39,8 @@ pub use crate::plumbing::{QueryCtxt, query_key_hash_verify_all}; mod profiling_support; pub use self::profiling_support::alloc_self_profile_query_strings; +mod error; + #[derive(ConstParamTy)] // Allow this struct to be used for const-generic values. #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct QueryFlags { diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index b074a9ca11b0..4147de7d2c4d 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -30,11 +30,11 @@ use rustc_query_system::query::{ QueryCache, QueryContext, QueryDispatcher, QueryJobId, QueryMap, QuerySideEffect, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, force_query, }; -use rustc_query_system::{QueryOverflow, QueryOverflowNote}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::def_id::LOCAL_CRATE; use crate::QueryDispatcherUnerased; +use crate::error::{QueryOverflow, QueryOverflowNote}; /// Implements [`QueryContext`] for use by [`rustc_query_system`], since that /// crate does not have direct access to [`TyCtxt`]. diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 55f2feba0d86..adce85bf31be 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,7 +1,6 @@ use rustc_errors::codes::*; -use rustc_hir::limit::Limit; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; #[derive(Subdiagnostic)] #[note("...which requires {$desc}...")] @@ -75,24 +74,3 @@ pub(crate) struct IncrementCompilation { pub run_cmd: String, pub dep_node: String, } - -#[derive(Diagnostic)] -#[help( - "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)" -)] -#[diag("queries overflow the depth limit!")] -pub struct QueryOverflow { - #[primary_span] - pub span: Span, - #[subdiagnostic] - pub note: QueryOverflowNote, - pub suggested_limit: Limit, - pub crate_name: Symbol, -} - -#[derive(Subdiagnostic)] -#[note("query depth increased by {$depth} when {$desc}")] -pub struct QueryOverflowNote { - pub desc: String, - pub depth: usize, -} diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 3175dbb54bea..61edf397886b 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -10,5 +10,3 @@ pub mod dep_graph; mod error; pub mod ich; pub mod query; - -pub use error::{QueryOverflow, QueryOverflowNote};