Skip to content

Commit 707c0d9

Browse files
authored
Rollup merge of rust-lang#98881 - cjgillot:q-def-kind, r=fee1-dead
Only compute DefKind through the query.
2 parents 5b8cf49 + 3162986 commit 707c0d9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ impl<'hir> Map<'hir> {
225225
self.tcx.definitions_untracked().iter_local_def_id()
226226
}
227227

228-
pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
228+
/// Do not call this function directly. The query should be called.
229+
pub(super) fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
229230
let hir_id = self.local_def_id_to_hir_id(local_def_id);
230231
let def_kind = match self.find(hir_id)? {
231232
Node::Item(item) => match item.kind {

compiler/rustc_privacy/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
467467
}
468468

469469
let macro_module_def_id = self.tcx.local_parent(local_def_id);
470-
if self.tcx.hir().opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) {
470+
if self.tcx.opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) {
471471
// The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252).
472472
return;
473473
}

compiler/rustc_query_impl/src/plumbing.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,14 @@ macro_rules! define_queries {
282282
} else {
283283
Some(key.default_span(*tcx))
284284
};
285-
// Use `tcx.hir().opt_def_kind()` to reduce the chance of
286-
// accidentally triggering an infinite query loop.
287-
let def_kind = key.key_as_def_id()
288-
.and_then(|def_id| def_id.as_local())
289-
.and_then(|def_id| tcx.hir().opt_def_kind(def_id));
285+
let def_kind = if kind == dep_graph::DepKind::opt_def_kind {
286+
// Try to avoid infinite recursion.
287+
None
288+
} else {
289+
key.key_as_def_id()
290+
.and_then(|def_id| def_id.as_local())
291+
.and_then(|def_id| tcx.opt_def_kind(def_id))
292+
};
290293
let hash = || {
291294
let mut hcx = tcx.create_stable_hashing_context();
292295
let mut hasher = StableHasher::new();

0 commit comments

Comments
 (0)