@@ -1034,16 +1034,23 @@ pub struct FreeRegionInfo {
10341034
10351035/// This struct should only be created by `create_def`.
10361036#[ derive( Copy , Clone ) ]
1037- pub struct TyCtxtFeed < ' tcx > {
1037+ pub struct TyCtxtFeed < ' tcx , KEY : Copy > {
10381038 pub tcx : TyCtxt < ' tcx > ,
10391039 // Do not allow direct access, as downstream code must not mutate this field.
1040- def_id : LocalDefId ,
1040+ key : KEY ,
10411041}
10421042
1043- impl < ' tcx > TyCtxtFeed < ' tcx > {
1043+ impl < ' tcx , KEY : Copy > TyCtxtFeed < ' tcx , KEY > {
1044+ #[ inline( always) ]
1045+ pub fn key ( & self ) -> KEY {
1046+ self . key
1047+ }
1048+ }
1049+
1050+ impl < ' tcx > TyCtxtFeed < ' tcx , LocalDefId > {
10441051 #[ inline( always) ]
10451052 pub fn def_id ( & self ) -> LocalDefId {
1046- self . def_id
1053+ self . key
10471054 }
10481055}
10491056
@@ -1515,7 +1522,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
15151522 self ,
15161523 parent : LocalDefId ,
15171524 data : hir:: definitions:: DefPathData ,
1518- ) -> TyCtxtFeed < ' tcx > {
1525+ ) -> TyCtxtFeed < ' tcx , LocalDefId > {
15191526 // This function modifies `self.definitions` using a side-effect.
15201527 // We need to ensure that these side effects are re-run by the incr. comp. engine.
15211528 // Depending on the forever-red node will tell the graph that the calling query
@@ -1536,9 +1543,9 @@ impl<'tcx> TyCtxtAt<'tcx> {
15361543 // This is fine because:
15371544 // - those queries are `eval_always` so we won't miss their result changing;
15381545 // - this write will have happened before these queries are called.
1539- let def_id = self . definitions . write ( ) . create_def ( parent, data) ;
1546+ let key = self . definitions . write ( ) . create_def ( parent, data) ;
15401547
1541- let feed = TyCtxtFeed { tcx : self . tcx , def_id } ;
1548+ let feed = TyCtxtFeed { tcx : self . tcx , key } ;
15421549 feed. def_span ( self . span ) ;
15431550 feed
15441551 }
0 commit comments