diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-08-29 19:02:47 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-08-29 19:38:47 -0700 |
| commit | d96234bed72e1935d8ab9a0c7a7e70027c86ad77 (patch) | |
| tree | c0b80db73e86b736b4d6a2604f7e63de15de2d12 /compiler/rustc_query_impl | |
| parent | c3df8328241bc0b10a5a77fae532aec795869c20 (diff) | |
| download | rust-d96234bed72e1935d8ab9a0c7a7e70027c86ad77.tar.gz rust-d96234bed72e1935d8ab9a0c7a7e70027c86ad77.zip | |
Retrieve `DefKind` from HIR map to reduce chance of cycles
`tcx.def_kind()` could theoretically invoke another query, which could cause an infinite query loop. Accessing the HIR map directly makes that less likely to happen. I also changed it to use `as_local()` (`tcx.def_kind()` seems to implicitly call `expect_local()`) and `opt_def_kind()` to reduce the chance of panicking on valid code.
Diffstat (limited to 'compiler/rustc_query_impl')
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 476085c8725..90a6ba474b4 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -338,10 +338,12 @@ macro_rules! define_queries { Some(key.default_span(*tcx)) }; let def_id = key.key_as_def_id(); - let def_kind = def_id.map(|def_id| { - let def_kind = tcx.def_kind(def_id); - $crate::util::def_kind_to_simple_def_kind(def_kind) - }); + let def_kind = def_id + .and_then(|def_id| def_id.as_local()) + // Use `tcx.hir().opt_def_kind()` to reduce the chance of + // accidentally triggering an infinite query loop. + .and_then(|def_id| tcx.hir().opt_def_kind(def_id)) + .map(|def_kind| $crate::util::def_kind_to_simple_def_kind(def_kind)); let hash = || { let mut hcx = tcx.create_stable_hashing_context(); let mut hasher = StableHasher::new(); |
