@@ -40,6 +40,8 @@ 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
42
use rustc_data_structures:: sync:: { self , FreezeReadGuard , Lock , Lrc , 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 ,
@@ -520,6 +522,16 @@ pub struct TyCtxt<'tcx> {
520
522
gcx : & ' tcx GlobalCtxt < ' tcx > ,
521
523
}
522
524
525
+ // Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution.
526
+ #[ cfg( parallel_compiler) ]
527
+ unsafe impl DynSend for TyCtxt < ' _ > { }
528
+ #[ cfg( parallel_compiler) ]
529
+ unsafe impl DynSync for TyCtxt < ' _ > { }
530
+ fn _assert_tcx_fields ( ) {
531
+ sync:: assert_dyn_sync :: < & ' _ GlobalCtxt < ' _ > > ( ) ;
532
+ sync:: assert_dyn_send :: < & ' _ GlobalCtxt < ' _ > > ( ) ;
533
+ }
534
+
523
535
impl < ' tcx > Deref for TyCtxt < ' tcx > {
524
536
type Target = & ' tcx GlobalCtxt < ' tcx > ;
525
537
#[ inline( always) ]
0 commit comments