Skip to content

Commit b60717f

Browse files
committed
Explicitly implement DynSync and DynSend for TyCtxt
1 parent 1d6f05f commit b60717f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
4040
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4141
use rustc_data_structures::steal::Steal;
4242
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal};
43+
#[cfg(parallel_compiler)]
44+
use rustc_data_structures::sync::{DynSend, DynSync};
4345
use rustc_data_structures::unord::UnordSet;
4446
use rustc_errors::{
4547
DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
@@ -520,6 +522,16 @@ pub struct TyCtxt<'tcx> {
520522
gcx: &'tcx GlobalCtxt<'tcx>,
521523
}
522524

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+
523535
impl<'tcx> Deref for TyCtxt<'tcx> {
524536
type Target = &'tcx GlobalCtxt<'tcx>;
525537
#[inline(always)]

0 commit comments

Comments
 (0)