@@ -6,6 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
66use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
77use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
88use rustc_errors:: Diagnostic ;
9+ use rustc_hir:: def_id:: DefId ;
910use rustc_index:: vec:: { Idx , IndexVec } ;
1011use smallvec:: SmallVec ;
1112use std:: collections:: hash_map:: Entry ;
@@ -677,18 +678,33 @@ impl DepGraph {
677678 } else {
678679 match dep_dep_node. kind {
679680 DepKind :: Hir | DepKind :: HirBody | DepKind :: CrateMetadata => {
680- if dep_dep_node. extract_def_id ( tcx) . is_none ( ) {
681+ if let Some ( def_id) = dep_dep_node. extract_def_id ( tcx) {
682+ if def_id_corresponds_to_hir_dep_node ( tcx, def_id) {
683+ // The `DefPath` has corresponding node,
684+ // and that node should have been marked
685+ // either red or green in `data.colors`.
686+ bug ! (
687+ "DepNode {:?} should have been \
688+ pre-marked as red or green but wasn't.",
689+ dep_dep_node
690+ ) ;
691+ } else {
692+ // This `DefPath` does not have a
693+ // corresponding `DepNode` (e.g. a
694+ // struct field), and the ` DefPath`
695+ // collided with the `DefPath` of a
696+ // proper item that existed in the
697+ // previous compilation session.
698+ //
699+ // Since the given `DefPath` does not
700+ // denote the item that previously
701+ // existed, we just fail to mark green.
702+ return None ;
703+ }
704+ } else {
681705 // If the node does not exist anymore, we
682706 // just fail to mark green.
683707 return None ;
684- } else {
685- // If the node does exist, it should have
686- // been pre-allocated.
687- bug ! (
688- "DepNode {:?} should have been \
689- pre-allocated but wasn't.",
690- dep_dep_node
691- )
692708 }
693709 }
694710 _ => {
@@ -899,6 +915,11 @@ impl DepGraph {
899915 }
900916}
901917
918+ fn def_id_corresponds_to_hir_dep_node ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
919+ let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
920+ def_id. index == hir_id. owner
921+ }
922+
902923/// A "work product" is an intermediate result that we save into the
903924/// incremental directory for later re-use. The primary example are
904925/// the object files that we save for each partition at code
0 commit comments