Remove Deref/DerefMut impl for Providers.

It's described as a "backwards compatibility hack to keep the diff
small". Removing it requires only a modest amount of churn, and the
resulting code is clearer without the invisible derefs.
This commit is contained in:
Nicholas Nethercote 2026-01-14 10:30:08 +11:00
parent aefa10405d
commit 3aa31788b5
17 changed files with 72 additions and 87 deletions

View file

@ -286,7 +286,8 @@ impl CodegenBackend for GccCodegenBackend {
}
fn provide(&self, providers: &mut Providers) {
providers.global_backend_features = |tcx, ()| gcc_util::global_gcc_features(tcx.sess)
providers.queries.global_backend_features =
|tcx, ()| gcc_util::global_gcc_features(tcx.sess)
}
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {

View file

@ -264,7 +264,7 @@ impl CodegenBackend for LlvmCodegenBackend {
}
fn provide(&self, providers: &mut Providers) {
providers.global_backend_features =
providers.queries.global_backend_features =
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, false)
}

View file

@ -474,15 +474,15 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId)
}
pub(crate) fn provide(providers: &mut Providers) {
providers.reachable_non_generics = reachable_non_generics_provider;
providers.is_reachable_non_generic = is_reachable_non_generic_provider_local;
providers.exported_non_generic_symbols = exported_non_generic_symbols_provider_local;
providers.exported_generic_symbols = exported_generic_symbols_provider_local;
providers.upstream_monomorphizations = upstream_monomorphizations_provider;
providers.is_unreachable_local_definition = is_unreachable_local_definition_provider;
providers.upstream_drop_glue_for = upstream_drop_glue_for_provider;
providers.upstream_async_drop_glue_for = upstream_async_drop_glue_for_provider;
providers.wasm_import_module_map = wasm_import_module_map;
providers.queries.reachable_non_generics = reachable_non_generics_provider;
providers.queries.is_reachable_non_generic = is_reachable_non_generic_provider_local;
providers.queries.exported_non_generic_symbols = exported_non_generic_symbols_provider_local;
providers.queries.exported_generic_symbols = exported_generic_symbols_provider_local;
providers.queries.upstream_monomorphizations = upstream_monomorphizations_provider;
providers.queries.is_unreachable_local_definition = is_unreachable_local_definition_provider;
providers.queries.upstream_drop_glue_for = upstream_drop_glue_for_provider;
providers.queries.upstream_async_drop_glue_for = upstream_async_drop_glue_for_provider;
providers.queries.wasm_import_module_map = wasm_import_module_map;
providers.extern_queries.is_reachable_non_generic = is_reachable_non_generic_provider_extern;
providers.extern_queries.upstream_monomorphizations_for =
upstream_monomorphizations_for_provider;

View file

@ -266,9 +266,9 @@ pub enum CodegenErrors {
pub fn provide(providers: &mut Providers) {
crate::back::symbol_export::provide(providers);
crate::base::provide(providers);
crate::target_features::provide(providers);
crate::codegen_attrs::provide(providers);
crate::base::provide(&mut providers.queries);
crate::target_features::provide(&mut providers.queries);
crate::codegen_attrs::provide(&mut providers.queries);
providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| vec![];
}

View file

@ -30,20 +30,20 @@ pub use self::errors::ReportErrorExt;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn provide(providers: &mut Providers) {
const_eval::provide(providers);
providers.tag_for_variant = const_eval::tag_for_variant_provider;
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
providers.eval_static_initializer = const_eval::eval_static_initializer_provider;
const_eval::provide(&mut providers.queries);
providers.queries.tag_for_variant = const_eval::tag_for_variant_provider;
providers.queries.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.queries.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
providers.queries.eval_static_initializer = const_eval::eval_static_initializer_provider;
providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
providers.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| {
providers.queries.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| {
const_eval::eval_to_valtree(tcx, typing_env, value)
};
providers.hooks.try_destructure_mir_constant_for_user_output =
const_eval::try_destructure_mir_constant_for_user_output;
providers.valtree_to_const_val =
providers.queries.valtree_to_const_val =
|tcx, cv| const_eval::valtree_to_const_value(tcx, ty::TypingEnv::fully_monomorphized(), cv);
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
providers.queries.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
};
providers.hooks.validate_scalar_in_layout =

View file

@ -880,36 +880,36 @@ pub fn write_interface<'tcx>(tcx: TyCtxt<'tcx>) {
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
let providers = &mut Providers::default();
providers.analysis = analysis;
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
providers.resolver_for_lowering_raw = resolver_for_lowering_raw;
providers.stripped_cfg_items = |tcx, _| &tcx.resolutions(()).stripped_cfg_items[..];
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
providers.early_lint_checks = early_lint_checks;
providers.env_var_os = env_var_os;
limits::provide(providers);
proc_macro_decls::provide(providers);
providers.queries.analysis = analysis;
providers.queries.hir_crate = rustc_ast_lowering::lower_to_hir;
providers.queries.resolver_for_lowering_raw = resolver_for_lowering_raw;
providers.queries.stripped_cfg_items = |tcx, _| &tcx.resolutions(()).stripped_cfg_items[..];
providers.queries.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
providers.queries.early_lint_checks = early_lint_checks;
providers.queries.env_var_os = env_var_os;
limits::provide(&mut providers.queries);
proc_macro_decls::provide(&mut providers.queries);
rustc_const_eval::provide(providers);
rustc_middle::hir::provide(providers);
rustc_borrowck::provide(providers);
rustc_middle::hir::provide(&mut providers.queries);
rustc_borrowck::provide(&mut providers.queries);
rustc_incremental::provide(providers);
rustc_mir_build::provide(providers);
rustc_mir_transform::provide(providers);
rustc_monomorphize::provide(providers);
rustc_privacy::provide(providers);
rustc_privacy::provide(&mut providers.queries);
rustc_query_impl::provide(providers);
rustc_resolve::provide(providers);
rustc_hir_analysis::provide(providers);
rustc_hir_typeck::provide(providers);
ty::provide(providers);
traits::provide(providers);
solve::provide(providers);
rustc_passes::provide(providers);
rustc_traits::provide(providers);
rustc_ty_utils::provide(providers);
rustc_resolve::provide(&mut providers.queries);
rustc_hir_analysis::provide(&mut providers.queries);
rustc_hir_typeck::provide(&mut providers.queries);
ty::provide(&mut providers.queries);
traits::provide(&mut providers.queries);
solve::provide(&mut providers.queries);
rustc_passes::provide(&mut providers.queries);
rustc_traits::provide(&mut providers.queries);
rustc_ty_utils::provide(&mut providers.queries);
rustc_metadata::provide(providers);
rustc_lint::provide(providers);
rustc_symbol_mangling::provide(providers);
rustc_lint::provide(&mut providers.queries);
rustc_symbol_mangling::provide(&mut providers.queries);
rustc_codegen_ssa::provide(providers);
*providers
});

View file

@ -585,6 +585,6 @@ const SYMBOL_OFFSET: u8 = 1;
const SYMBOL_PREDEFINED: u8 = 2;
pub fn provide(providers: &mut Providers) {
encoder::provide(providers);
encoder::provide(&mut providers.queries);
decoder::provide(providers);
}

View file

@ -6,20 +6,3 @@ pub struct Providers {
pub extern_queries: crate::query::ExternProviders,
pub hooks: crate::hooks::Providers,
}
/// Backwards compatibility hack to keep the diff small. This
/// gives direct access to the `queries` field's fields, which
/// are what almost everything wants access to.
impl std::ops::DerefMut for Providers {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.queries
}
}
impl std::ops::Deref for Providers {
type Target = crate::query::Providers;
fn deref(&self) -> &Self::Target {
&self.queries
}
}

View file

@ -23,12 +23,12 @@ use rustc_middle::util::Providers;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn provide(providers: &mut Providers) {
providers.check_match = thir::pattern::check_match;
providers.lit_to_const = thir::constant::lit_to_const;
providers.closure_saved_names_of_captured_variables =
providers.queries.check_match = thir::pattern::check_match;
providers.queries.lit_to_const = thir::constant::lit_to_const;
providers.queries.closure_saved_names_of_captured_variables =
builder::closure_saved_names_of_captured_variables;
providers.check_unsafety = check_unsafety::check_unsafety;
providers.check_tail_calls = check_tail_calls::check_tail_calls;
providers.thir_body = thir::cx::thir_body;
providers.queries.check_unsafety = check_unsafety::check_unsafety;
providers.queries.check_tail_calls = check_tail_calls::check_tail_calls;
providers.queries.thir_body = thir::cx::thir_body;
providers.hooks.build_mir_inner_impl = builder::build_mir_inner_impl;
}

View file

@ -206,9 +206,9 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn provide(providers: &mut Providers) {
coverage::query::provide(providers);
ffi_unwind_calls::provide(providers);
shim::provide(providers);
cross_crate_inline::provide(providers);
ffi_unwind_calls::provide(&mut providers.queries);
shim::provide(&mut providers.queries);
cross_crate_inline::provide(&mut providers.queries);
providers.queries = query::Providers {
mir_keys,
mir_built,

View file

@ -1825,5 +1825,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
pub(crate) fn provide(providers: &mut Providers) {
providers.hooks.should_codegen_locally = should_codegen_locally;
providers.items_of_instance = items_of_instance;
providers.queries.items_of_instance = items_of_instance;
}

View file

@ -52,5 +52,5 @@ fn custom_coerce_unsize_info<'tcx>(
pub fn provide(providers: &mut Providers) {
partitioning::provide(providers);
mono_checks::provide(providers);
mono_checks::provide(&mut providers.queries);
}

View file

@ -1313,12 +1313,12 @@ fn dump_mono_items_stats<'tcx>(
}
pub(crate) fn provide(providers: &mut Providers) {
providers.collect_and_partition_mono_items = collect_and_partition_mono_items;
providers.queries.collect_and_partition_mono_items = collect_and_partition_mono_items;
providers.is_codegened_item =
providers.queries.is_codegened_item =
|tcx, def_id| tcx.collect_and_partition_mono_items(()).all_mono_items.contains(&def_id);
providers.codegen_unit = |tcx, name| {
providers.queries.codegen_unit = |tcx, name| {
tcx.collect_and_partition_mono_items(())
.codegen_units
.iter()
@ -1326,7 +1326,7 @@ pub(crate) fn provide(providers: &mut Providers) {
.unwrap_or_else(|| panic!("failed to find cgu with name {name:?}"))
};
providers.size_estimate = |tcx, instance| {
providers.queries.size_estimate = |tcx, instance| {
match instance.def {
// "Normal" functions size estimate: the number of
// statements, plus one for the terminator.

View file

@ -9,7 +9,7 @@
#![feature(map_try_insert)]
// tidy-alphabetical-end
use rustc_middle::util::Providers;
use rustc_middle::query::Providers;
pub mod abi_test;
mod check_attr;

View file

@ -297,14 +297,15 @@ pub(crate) fn create_config(
override_queries: Some(|_sess, providers| {
// We do not register late module lints, so this only runs `MissingDoc`.
// Most lints will require typechecking, so just don't run them.
providers.lint_mod = |tcx, module_def_id| late_lint_mod(tcx, module_def_id, MissingDoc);
providers.queries.lint_mod =
|tcx, module_def_id| late_lint_mod(tcx, module_def_id, MissingDoc);
// hack so that `used_trait_imports` won't try to call typeck
providers.used_trait_imports = |_, _| {
providers.queries.used_trait_imports = |_, _| {
static EMPTY_SET: LazyLock<UnordSet<LocalDefId>> = LazyLock::new(UnordSet::default);
&EMPTY_SET
};
// In case typeck does end up being called, don't ICE in case there were name resolution errors
providers.typeck = move |tcx, def_id| {
providers.queries.typeck = move |tcx, def_id| {
// Closures' tables come from their outermost function,
// as they are part of the same "inference environment".
// This avoids emitting errors for the parent twice (see similar code in `typeck_with_fallback`)
@ -316,7 +317,7 @@ pub(crate) fn create_config(
let body = tcx.hir_body_owned_by(def_id);
debug!("visiting body for {def_id:?}");
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
(rustc_interface::DEFAULT_QUERY_PROVIDERS.queries.typeck)(tcx, def_id)
};
}),
extra_symbols: Vec::new(),

View file

@ -305,7 +305,7 @@ impl rustc_driver::Callbacks for MiriDepCompilerCalls {
config.override_queries = Some(|_, local_providers| {
// We need to add #[used] symbols to exported_symbols for `lookup_link_section`.
// FIXME handle this somehow in rustc itself to avoid this hack.
local_providers.exported_non_generic_symbols = |tcx, LocalCrate| {
local_providers.queries.exported_non_generic_symbols = |tcx, LocalCrate| {
let reachable_set = tcx
.with_stable_hashing_context(|hcx| tcx.reachable_set(()).to_sorted(&hcx, true));
tcx.arena.alloc_from_iter(

View file

@ -114,7 +114,7 @@ impl rustc_driver::Callbacks for CompilerCalls {
}
fn override_queries(_session: &Session, local: &mut Providers) {
local.mir_borrowck = mir_borrowck;
local.queries.mir_borrowck = mir_borrowck;
}
// Since mir_borrowck does not have access to any other state, we need to use a
@ -142,8 +142,8 @@ fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ProvidedValue<'t
}
});
let mut providers = Providers::default();
rustc_borrowck::provide(&mut providers);
let original_mir_borrowck = providers.mir_borrowck;
rustc_borrowck::provide(&mut providers.queries);
let original_mir_borrowck = providers.queries.mir_borrowck;
original_mir_borrowck(tcx, def_id)
}