Skip to content

Commit 20bed53

Browse files
Rollup merge of #153999 - Zoxc:rem-TaggedQueryKey-def_kind-uses, r=petrochenkov
Remove `TaggedQueryKey::def_kind` This removes `TaggedQueryKey::def_kind` by accessing the relevant query keys directly.
2 parents a5ff88b + e6098df commit 20bed53

2 files changed

Lines changed: 16 additions & 30 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -464,30 +464,6 @@ macro_rules! define_callbacks {
464464
)*
465465
}
466466
}
467-
468-
pub fn def_kind(&self, tcx: TyCtxt<'tcx>) -> Option<DefKind> {
469-
// This is used to reduce code generation as it
470-
// can be reused for queries with the same key type.
471-
fn inner<'tcx>(key: &impl $crate::query::QueryKey, tcx: TyCtxt<'tcx>)
472-
-> Option<DefKind>
473-
{
474-
key
475-
.key_as_def_id()
476-
.and_then(|def_id| def_id.as_local())
477-
.map(|def_id| tcx.def_kind(def_id))
478-
}
479-
480-
if let TaggedQueryKey::def_kind(..) = self {
481-
// Try to avoid infinite recursion.
482-
return None
483-
}
484-
485-
match self {
486-
$(
487-
TaggedQueryKey::$name(key) => inner(key, tcx),
488-
)*
489-
}
490-
}
491467
}
492468

493469
/// Holds a `QueryVTable` for each query.

compiler/rustc_query_impl/src/job.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,23 @@ pub(crate) fn create_cycle_error<'tcx>(
481481
usage: usage.tagged_key.description(tcx),
482482
});
483483

484-
let alias = if frames
485-
.iter()
486-
.all(|frame| frame.tagged_key.def_kind(tcx) == Some(DefKind::TyAlias))
487-
{
484+
let is_all_def_kind = |def_kind| {
485+
// Trivial type alias and trait alias cycles consists of `type_of` and
486+
// `explicit_implied_predicates_of` queries, so we just check just these here.
487+
frames.iter().all(|frame| match frame.tagged_key {
488+
TaggedQueryKey::type_of(def_id)
489+
| TaggedQueryKey::explicit_implied_predicates_of(def_id)
490+
if tcx.def_kind(def_id) == def_kind =>
491+
{
492+
true
493+
}
494+
_ => false,
495+
})
496+
};
497+
498+
let alias = if is_all_def_kind(DefKind::TyAlias) {
488499
Some(crate::error::Alias::Ty)
489-
} else if frames.iter().all(|frame| frame.tagged_key.def_kind(tcx) == Some(DefKind::TraitAlias))
490-
{
500+
} else if is_all_def_kind(DefKind::TraitAlias) {
491501
Some(crate::error::Alias::Trait)
492502
} else {
493503
None

0 commit comments

Comments
 (0)