diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index d0b5a7a1860f0..7853d7fa86cab 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -1339,6 +1339,8 @@ impl CurrentDepGraph { prev_graph: &SerializedDepGraph, prev_index: SerializedDepNodeIndex, ) -> DepNodeIndex { + self.debug_assert_not_in_new_nodes(prev_graph, prev_index); + let mut prev_index_to_index = self.prev_index_to_index.lock(); match prev_index_to_index[prev_index] { @@ -1359,6 +1361,22 @@ impl CurrentDepGraph { } } } + + #[inline] + fn debug_assert_not_in_new_nodes( + &self, + prev_graph: &SerializedDepGraph, + prev_index: SerializedDepNodeIndex, + ) { + let node = &prev_graph.index_to_node(prev_index); + debug_assert!( + !self + .nodes_newly_allocated_in_current_session + .as_ref() + .map_or(false, |set| set.lock().contains(node)), + "node from previous graph present in new node collection" + ); + } } /// The capacity of the `reads` field `SmallVec`