diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 04e49d962b23f..0a46ef0f8d6b9 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -43,6 +43,9 @@ pub struct Compiler { pub compiler_for_deadlock_handler: Arc>, } +impl !Sync for Compiler {} +impl !rustc_data_structures::sync::DynSync for Compiler {} + /// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`. pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg { cfgs.into_iter() diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index d0ce23dacb5ef..d4942d7e2f40b 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -4,6 +4,7 @@ #![feature(let_chains)] #![feature(thread_spawn_unchecked)] #![feature(try_blocks)] +#![feature(negative_impls)] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index eb2c6b70c6f81..0face90d040e4 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -161,9 +161,11 @@ impl<'tcx> Queries<'tcx> { &self.hir_arena, ); - self.compiler + let old = self + .compiler .compiler_for_deadlock_handler - .store(qcx as *const _ as *mut _, Ordering::Relaxed); + .swap(qcx as *const _ as *mut _, Ordering::Relaxed); + assert!(old.is_null()); qcx.enter(|tcx| { let feed = tcx.feed_local_crate(); @@ -321,6 +323,7 @@ impl Compiler { // is accessing the `GlobalCtxt`. self.compiler_for_deadlock_handler.store(std::ptr::null_mut(), Ordering::Relaxed); }); + assert!(self.compiler_for_deadlock_handler.load(Ordering::Relaxed).is_null()); let queries = Queries::new(self); let ret = f(&queries);