@@ -39,7 +39,9 @@ use rustc_data_structures::profiling::SelfProfilerRef;
39
39
use rustc_data_structures:: sharded:: { IntoPointer , ShardedHashMap } ;
40
40
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
41
41
use rustc_data_structures:: steal:: Steal ;
42
- use rustc_data_structures:: sync:: { FreezeReadGuard , Lock , WorkerLocal } ;
42
+ use rustc_data_structures:: sync:: { self , FreezeReadGuard , Lock , WorkerLocal } ;
43
+ #[ cfg( parallel_compiler) ]
44
+ use rustc_data_structures:: sync:: { DynSend , DynSync } ;
43
45
use rustc_data_structures:: unord:: UnordSet ;
44
46
use rustc_errors:: {
45
47
DecorateLint , DiagnosticBuilder , DiagnosticMessage , ErrorGuaranteed , MultiSpan ,
@@ -552,6 +554,16 @@ pub struct TyCtxt<'tcx> {
552
554
gcx : & ' tcx GlobalCtxt < ' tcx > ,
553
555
}
554
556
557
+ // Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution.
558
+ #[ cfg( parallel_compiler) ]
559
+ unsafe impl DynSend for TyCtxt < ' _ > { }
560
+ #[ cfg( parallel_compiler) ]
561
+ unsafe impl DynSync for TyCtxt < ' _ > { }
562
+ fn _assert_tcx_fields ( ) {
563
+ sync:: assert_dyn_sync :: < & ' _ GlobalCtxt < ' _ > > ( ) ;
564
+ sync:: assert_dyn_send :: < & ' _ GlobalCtxt < ' _ > > ( ) ;
565
+ }
566
+
555
567
impl < ' tcx > Deref for TyCtxt < ' tcx > {
556
568
type Target = & ' tcx GlobalCtxt < ' tcx > ;
557
569
#[ inline( always) ]
0 commit comments