explicitly implement !Send and !Sync

This commit is contained in:
cyrgani 2025-09-30 00:09:12 +02:00
parent 23f3400613
commit d7773f6b1c
4 changed files with 12 additions and 31 deletions

View File

@ -26,18 +26,16 @@ macro_rules! define_client_handles {
$(
pub(crate) struct $oty {
handle: handle::Handle,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}
impl !Send for $oty {}
impl !Sync for $oty {}
// Forward `Drop::drop` to the inherent `drop` method.
impl Drop for $oty {
fn drop(&mut self) {
$oty {
handle: self.handle,
_marker: PhantomData,
}.drop();
}
}
@ -64,7 +62,6 @@ macro_rules! define_client_handles {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$oty {
handle: handle::Handle::decode(r, s),
_marker: PhantomData,
}
}
}
@ -74,12 +71,11 @@ macro_rules! define_client_handles {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct $ity {
handle: handle::Handle,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}
impl !Send for $ity {}
impl !Sync for $ity {}
impl<S> Encode<S> for $ity {
fn encode(self, w: &mut Writer, s: &mut S) {
self.handle.encode(w, s);
@ -90,7 +86,6 @@ macro_rules! define_client_handles {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$ity {
handle: handle::Handle::decode(r, s),
_marker: PhantomData,
}
}
}

View File

@ -6,9 +6,7 @@ use std::marker::PhantomData;
pub(super) struct Closure<'a, A, R> {
call: unsafe extern "C" fn(*mut Env, A) -> R,
env: *mut Env,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
// Prevent Send and Sync impls.
//
// The `'a` lifetime parameter represents the lifetime of `Env`.
_marker: PhantomData<*mut &'a mut ()>,

View File

@ -160,13 +160,11 @@ pub struct BridgeConfig<'a> {
/// If 'true', always invoke the default panic hook
force_show_panics: bool,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
_marker: marker::PhantomData<*mut ()>,
}
impl !Send for BridgeConfig<'_> {}
impl !Sync for BridgeConfig<'_> {}
#[forbid(unsafe_code)]
#[allow(non_camel_case_types)]
mod api_tags {

View File

@ -295,12 +295,7 @@ impl ExecutionStrategy for SameThread {
let mut dispatch = |buf| dispatcher.dispatch(buf);
run_client(BridgeConfig {
input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
})
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
}
}
@ -331,12 +326,7 @@ where
client.recv().expect("server died while client waiting for reply")
};
run_client(BridgeConfig {
input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
})
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
});
while let Some(b) = server.recv() {