@@ -6,6 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
6
6
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
7
7
use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
8
8
use rustc_errors:: Diagnostic ;
9
+ use rustc_hir:: def_id:: DefId ;
9
10
use rustc_index:: vec:: { Idx , IndexVec } ;
10
11
use smallvec:: SmallVec ;
11
12
use std:: collections:: hash_map:: Entry ;
@@ -677,18 +678,33 @@ impl DepGraph {
677
678
} else {
678
679
match dep_dep_node. kind {
679
680
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 {
681
705
// If the node does not exist anymore, we
682
706
// just fail to mark green.
683
707
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
- )
692
708
}
693
709
}
694
710
_ => {
@@ -899,6 +915,11 @@ impl DepGraph {
899
915
}
900
916
}
901
917
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
+
902
923
/// A "work product" is an intermediate result that we save into the
903
924
/// incremental directory for later re-use. The primary example are
904
925
/// the object files that we save for each partition at code
0 commit comments