1
Fork 0

Only compute DefKind through the query.

This commit is contained in:
Camille GILLOT 2022-04-29 19:43:15 +02:00
parent 9a6fa4f118
commit e3d63203a3
3 changed files with 4 additions and 3 deletions

View file

@ -225,7 +225,8 @@ impl<'hir> Map<'hir> {
self.tcx.definitions_untracked().iter_local_def_id() self.tcx.definitions_untracked().iter_local_def_id()
} }
pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> { /// Do not call this function directly. The query should be called.
pub(super) fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
let hir_id = self.local_def_id_to_hir_id(local_def_id); let hir_id = self.local_def_id_to_hir_id(local_def_id);
let def_kind = match self.find(hir_id)? { let def_kind = match self.find(hir_id)? {
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {

View file

@ -467,7 +467,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
} }
let macro_module_def_id = self.tcx.local_parent(local_def_id); let macro_module_def_id = self.tcx.local_parent(local_def_id);
if self.tcx.hir().opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) { if self.tcx.opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) {
// The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252). // The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252).
return; return;
} }

View file

@ -291,7 +291,7 @@ macro_rules! define_queries {
// accidentally triggering an infinite query loop. // accidentally triggering an infinite query loop.
let def_kind = key.key_as_def_id() let def_kind = key.key_as_def_id()
.and_then(|def_id| def_id.as_local()) .and_then(|def_id| def_id.as_local())
.and_then(|def_id| tcx.hir().opt_def_kind(def_id)); .map(|def_id| tcx.def_kind(def_id));
let hash = || { let hash = || {
let mut hcx = tcx.create_stable_hashing_context(); let mut hcx = tcx.create_stable_hashing_context();
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();