Skip to content

Commit e6098df

Browse files
committed
Remove TaggedQueryKey::def_kind
1 parent 0312931 commit e6098df

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

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
@@ -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)