Skip to content

Commit 58042bf

Browse files
authored
Rollup merge of #99340 - GoldsteinE:fix-localdefid-debug-ice, r=lcnr
Fix ICE in Definitions::create_def `Debug` implementation for `LocalDefId` uses global `Definitions`. Normally it’s ok, but we can’t do it while holding a mutable reference to `Definitions`, since it causes ICE or deadlock (depending on whether `parallel_compiler` is enabled). This PR effectively copies the `Debug` implementation into the problematic method. I don’t particularly love this solution (since it creates code duplication), but I don’t see any other options. This issue was discovered when running `rustdoc` with `RUSTDOC_LOG=trace` on the following file: ```rust pub struct SomeStruct; fn asdf() { impl SomeStruct { pub fn qwop(&self) { println!("hidden function"); } } } ``` I’m not sure how to create a test for this behavior.
2 parents 1f5d8d4 + d9f28b7 commit 58042bf

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_hir/src/definitions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ impl Definitions {
338338

339339
/// Adds a definition with a parent definition.
340340
pub fn create_def(&mut self, parent: LocalDefId, data: DefPathData) -> LocalDefId {
341-
debug!("create_def(parent={:?}, data={:?})", parent, data);
341+
// We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a
342+
// reference to `Definitions` and we're already holding a mutable reference.
343+
debug!(
344+
"create_def(parent={}, data={data:?})",
345+
self.def_path(parent).to_string_no_crate_verbose(),
346+
);
342347

343348
// The root node must be created with `create_root_def()`.
344349
assert!(data != DefPathData::CrateRoot);

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1459,11 +1459,11 @@ impl<'tcx> TyCtxt<'tcx> {
14591459
};
14601460

14611461
format!(
1462-
"{}[{}]{}",
1462+
"{}[{:04x}]{}",
14631463
crate_name,
14641464
// Don't print the whole stable crate id. That's just
14651465
// annoying in debug output.
1466-
&(format!("{:08x}", stable_crate_id.to_u64()))[..4],
1466+
stable_crate_id.to_u64() >> 8 * 6,
14671467
self.def_path(def_id).to_string_no_crate_verbose()
14681468
)
14691469
}

0 commit comments

Comments
 (0)