Skip to content

Commit f462a5b

Browse files
Rollup merge of #153210 - Delta17920:fix-query-dep-graph, r=jdonszelmann,JonathanBrouwer
Fix ICE on empty file with -Zquery-dep-graph added a guard in `DepGraph::register_dep_node_debug_str` so it early-returns when `self.data` is still `None`. this happens for the first few dep-nodes in an empty crate with `-Z query-dep-graph`, which caused the previous `unwrap()` panic. fixes #153199
2 parents d94d079 + 038b718 commit f462a5b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,13 @@ impl DepGraph {
826826
where
827827
F: FnOnce() -> String,
828828
{
829-
let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;
829+
// Early queries (e.g., `-Z query-dep-graph` on empty crates) can reach here
830+
// before the graph is initialized. Return early to prevent an ICE.
831+
let data = match &self.data {
832+
Some(d) => d,
833+
None => return,
834+
};
835+
let dep_node_debug = &data.dep_node_debug;
830836

831837
if dep_node_debug.borrow().contains_key(&dep_node) {
832838
return;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ build-pass
2+
//@ compile-flags: -Zquery-dep-graph --crate-type lib
3+
//@ edition: 2021
4+
5+
// This file is intentionally left empty to reproduce issue #153199.
6+
// rustc used to ICE when generating a dependency graph for an empty file
7+
// because early queries would panic when unwrapping an uninitialized graph.

0 commit comments

Comments
 (0)