Skip to content

Commit 6308ab9

Browse files
committed
Remove TaggedQueryKey::def_kind
1 parent bcf3d36 commit 6308ab9

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
@@ -448,30 +448,6 @@ macro_rules! define_callbacks {
448448
)*
449449
}
450450
}
451-
452-
pub fn def_kind(&self, tcx: TyCtxt<'tcx>) -> Option<DefKind> {
453-
// This is used to reduce code generation as it
454-
// can be reused for queries with the same key type.
455-
fn inner<'tcx>(key: &impl $crate::query::QueryKey, tcx: TyCtxt<'tcx>)
456-
-> Option<DefKind>
457-
{
458-
key
459-
.key_as_def_id()
460-
.and_then(|def_id| def_id.as_local())
461-
.map(|def_id| tcx.def_kind(def_id))
462-
}
463-
464-
if let TaggedQueryKey::def_kind(..) = self {
465-
// Try to avoid infinite recursion.
466-
return None
467-
}
468-
469-
match self {
470-
$(
471-
TaggedQueryKey::$name(key) => inner(key, tcx),
472-
)*
473-
}
474-
}
475451
}
476452

477453
/// 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
@@ -484,13 +484,23 @@ pub(crate) fn report_cycle<'tcx>(
484484
usage: usage.tagged_key.description(tcx),
485485
});
486486

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

0 commit comments

Comments
 (0)