Skip to content

Commit f600795

Browse files
committed
Fix ICE on empty file with -Zquery-dep-graph
1 parent 1eb36c6 commit f600795

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 of a duplicate DepNode registration hitting a debug_assert.

0 commit comments

Comments
 (0)