Clarify the behaviour from inside the query system.

This commit is contained in:
Camille GILLOT 2022-07-05 22:52:21 +02:00
parent e3d63203a3
commit 974b1e3e51

View file

@ -287,11 +287,14 @@ macro_rules! define_queries {
} else { } else {
Some(key.default_span(*tcx)) Some(key.default_span(*tcx))
}; };
// Use `tcx.hir().opt_def_kind()` to reduce the chance of let def_kind = if kind == dep_graph::DepKind::opt_def_kind {
// accidentally triggering an infinite query loop. // Try to avoid infinite recursion.
let def_kind = key.key_as_def_id() None
.and_then(|def_id| def_id.as_local()) } else {
.map(|def_id| tcx.def_kind(def_id)); key.key_as_def_id()
.and_then(|def_id| def_id.as_local())
.and_then(|def_id| tcx.opt_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();