1515use dep_graph:: { DepNodeIndex , DepNode , DepKind , DepNodeColor , OpenTask } ;
1616use errors:: DiagnosticBuilder ;
1717use errors:: Level ;
18+ use errors:: Diagnostic ;
1819use ty:: tls;
1920use ty:: { TyCtxt } ;
2021use ty:: query:: Query ;
@@ -289,13 +290,15 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
289290 & self ,
290291 tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
291292 task : & OpenTask ,
293+ diagnostics : Option < & Lock < Option < Box < Vec < Diagnostic > > > > > ,
292294 key : Q :: Key ,
293295 ) -> Q :: Value
294296 {
295297 // Update the ImplicitCtxt to point to our new query job
296298 let new_icx = tls:: ImplicitCtxt {
297299 tcx,
298300 query : Some ( LrcRef :: new ( & self . job ) ) ,
301+ diagnostics,
299302 layout_depth : self . layout_depth ,
300303 task,
301304 } ;
@@ -305,6 +308,17 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
305308 Q :: compute ( tcx, key)
306309 } )
307310 }
311+
312+ }
313+
314+ #[ inline( always) ]
315+ fn with_diagnostics < F , R > ( f : F ) -> ( R , Option < Box < Vec < Diagnostic > > > )
316+ where
317+ F : FnOnce ( Option < & Lock < Option < Box < Vec < Diagnostic > > > > > ) -> R
318+ {
319+ let diagnostics = Lock :: new ( None ) ;
320+ let result = f ( Some ( & diagnostics) ) ;
321+ ( result, diagnostics. into_inner ( ) )
308322}
309323
310324impl < ' a , ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' a , ' tcx , Q > {
@@ -489,8 +503,10 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
489503 profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
490504 self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
491505
492- let res = self . dep_graph . with_anon_open_task ( dep_node. kind , |open_task| {
493- job. compute ( self , open_task, key)
506+ let ( res, diag) = with_diagnostics ( |diagnostics| {
507+ self . dep_graph . with_anon_open_task ( dep_node. kind , |open_task| {
508+ job. compute ( self , open_task, diagnostics, key)
509+ } )
494510 } ) ;
495511
496512 self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
@@ -499,7 +515,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
499515
500516 self . dep_graph . read_index ( dep_node_index) ;
501517
502- if let Some ( diagnostics) = job . job . extract_diagnostics ( ) {
518+ if let Some ( diagnostics) = diag {
503519 self . queries . on_disk_cache
504520 . store_diagnostics_for_anon_node ( dep_node_index, diagnostics) ;
505521 }
@@ -573,7 +589,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
573589 // try_mark_green(), so we can ignore them here.
574590 // The dep-graph for this computation is already in
575591 // place so we pass OpenTask::Ignore.
576- job. compute ( self , & OpenTask :: Ignore , key)
592+ job. compute ( self , & OpenTask :: Ignore , None , key)
577593 } ;
578594
579595 // If -Zincremental-verify-ich is specified, re-hash results from
@@ -647,15 +663,17 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
647663 p. record_query ( Q :: CATEGORY ) ;
648664 } ) ;
649665
650- let ( result, dep_node_index) = if dep_node. kind . is_eval_always ( ) {
651- self . dep_graph . with_eval_always_task ( self , dep_node, |task| {
652- job. compute ( self , task, key)
653- } )
654- } else {
655- self . dep_graph . with_query_task ( self , dep_node, |task| {
656- job. compute ( self , task, key)
657- } )
658- } ;
666+ let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
667+ if dep_node. kind . is_eval_always ( ) {
668+ self . dep_graph . with_eval_always_task ( self , dep_node, |task| {
669+ job. compute ( self , task, diagnostics, key)
670+ } )
671+ } else {
672+ self . dep_graph . with_query_task ( self , dep_node, |task| {
673+ job. compute ( self , task, diagnostics, key)
674+ } )
675+ }
676+ } ) ;
659677
660678 self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
661679 profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
@@ -665,7 +683,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
665683 }
666684
667685 if dep_node. kind != :: dep_graph:: DepKind :: Null {
668- if let Some ( diagnostics) = job . job . extract_diagnostics ( ) {
686+ if let Some ( diagnostics) = diagnostics {
669687 self . queries . on_disk_cache
670688 . store_diagnostics ( dep_node_index, diagnostics) ;
671689 }
0 commit comments