From aebcf78527c38199c48aea2939d6e5062ea85e9e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 14 Jan 2026 14:12:59 +1100 Subject: [PATCH] Remove unused `Key`/`AsLocalKey` impls. --- compiler/rustc_middle/src/query/keys.rs | 166 +----------------------- 1 file changed, 3 insertions(+), 163 deletions(-) diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 4fa8ca7d85bd..cccb7d51bd3e 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -3,8 +3,8 @@ use std::ffi::OsStr; use rustc_ast::tokenstream::TokenStream; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId}; -use rustc_hir::hir_id::{HirId, OwnerId}; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; +use rustc_hir::hir_id::OwnerId; use rustc_query_system::dep_graph::DepNodeIndex; use rustc_query_system::query::{DefIdCache, DefaultCache, SingleCache, VecCache}; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; @@ -12,7 +12,7 @@ use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; use crate::infer::canonical::CanonicalQueryInput; use crate::mir::mono::CollectionMode; use crate::ty::fast_reject::SimplifiedType; -use crate::ty::layout::{TyAndLayout, ValidityRequirement}; +use crate::ty::layout::ValidityRequirement; use crate::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt}; use crate::{mir, traits}; @@ -69,15 +69,6 @@ impl<'tcx> Key for ty::InstanceKind<'tcx> { } } -impl<'tcx> AsLocalKey for ty::InstanceKind<'tcx> { - type LocalKey = Self; - - #[inline(always)] - fn as_local_key(&self) -> Option { - self.def_id().is_local().then(|| *self) - } -} - impl<'tcx> Key for ty::Instance<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id()) @@ -176,26 +167,6 @@ impl Key for LocalModDefId { } } -impl Key for ModDefId { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.def_span(*self) - } - - #[inline(always)] - fn key_as_def_id(&self) -> Option { - Some(self.to_def_id()) - } -} - -impl AsLocalKey for ModDefId { - type LocalKey = LocalModDefId; - - #[inline(always)] - fn as_local_key(&self) -> Option { - self.as_local() - } -} - impl Key for SimplifiedType { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -208,30 +179,6 @@ impl Key for (DefId, DefId) { } } -impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.default_span(tcx) - } -} - -impl Key for (DefId, LocalDefId) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.1.default_span(tcx) - } -} - -impl Key for (LocalDefId, DefId) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.default_span(tcx) - } -} - -impl Key for (LocalDefId, LocalDefId) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.default_span(tcx) - } -} - impl Key for (DefId, Ident) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.0) @@ -279,12 +226,6 @@ impl AsLocalKey for (CrateNum, SimplifiedType) { } } -impl Key for (DefId, SimplifiedType) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.default_span(tcx) - } -} - impl Key for (DefId, ty::SizedTraitKind) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -303,66 +244,18 @@ impl<'tcx> Key for (DefId, GenericArgsRef<'tcx>) { } } -impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - (self.0).def.default_span(tcx) - } -} - -impl<'tcx> Key for (LocalDefId, DefId, GenericArgsRef<'tcx>) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.default_span(tcx) - } -} - -impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::TraitRef<'tcx>) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.def_span(self.1.def_id) - } -} - -impl<'tcx> Key for ty::ParamEnvAnd<'tcx, Ty<'tcx>> { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx> Key for ty::TraitRef<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id) } } -impl<'tcx> Key for ty::PolyTraitRef<'tcx> { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.def_span(self.def_id()) - } -} - -impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.def_span(self.def_id()) - } -} - -impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.def_span(self.0.def_id()) - } -} - impl<'tcx> Key for GenericArg<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for ty::Const<'tcx> { - fn default_span(&self, _: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx> Key for Ty<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -377,12 +270,6 @@ impl<'tcx> Key for Ty<'tcx> { } } -impl<'tcx> Key for TyAndLayout<'tcx> { - fn default_span(&self, _: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -395,12 +282,6 @@ impl<'tcx> Key for ty::Clauses<'tcx> { } } -impl<'tcx> Key for ty::ParamEnv<'tcx> { - fn default_span(&self, _: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.value.default_span(tcx) @@ -443,18 +324,6 @@ impl<'tcx, T: Clone> Key for (CanonicalQueryInput<'tcx, T>, bool) { } } -impl Key for (Symbol, u32, u32) { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - -impl<'tcx> Key for (DefId, Ty<'tcx>, GenericArgsRef<'tcx>, ty::ParamEnv<'tcx>) { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP @@ -485,39 +354,10 @@ impl<'tcx> Key for ty::Value<'tcx> { } } -impl Key for HirId { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.hir_span(*self) - } - - #[inline(always)] - fn key_as_def_id(&self) -> Option { - None - } -} - -impl Key for (LocalDefId, HirId) { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.hir_span(self.1) - } - - #[inline(always)] - fn key_as_def_id(&self) -> Option { - Some(self.0.into()) - } -} - impl<'tcx> Key for (LocalExpnId, &'tcx TokenStream) { - type Cache = DefaultCache; - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { self.0.expn_data().call_site } - - #[inline(always)] - fn key_as_def_id(&self) -> Option { - None - } } impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) {