Fix ICE on empty file with -Zquery-dep-graph

This commit is contained in:
delta17920
2026-02-28 07:53:55 +00:00
parent 1eb36c6516
commit 038b718390
2 changed files with 14 additions and 1 deletions
+7 -1
View File
@@ -826,7 +826,13 @@ pub(crate) fn register_dep_node_debug_str<F>(&self, dep_node: DepNode, debug_str
where
F: FnOnce() -> String,
{
let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;
// Early queries (e.g., `-Z query-dep-graph` on empty crates) can reach here
// before the graph is initialized. Return early to prevent an ICE.
let data = match &self.data {
Some(d) => d,
None => return,
};
let dep_node_debug = &data.dep_node_debug;
if dep_node_debug.borrow().contains_key(&dep_node) {
return;
@@ -0,0 +1,7 @@
//@ build-pass
//@ compile-flags: -Zquery-dep-graph --crate-type lib
//@ edition: 2021
// This file is intentionally left empty to reproduce issue #153199.
// rustc used to ICE when generating a dependency graph for an empty file
// because early queries would panic when unwrapping an uninitialized graph.