Skip to content

Commit d7773f6

Browse files
committed
explicitly implement !Send and !Sync
1 parent 23f3400 commit d7773f6

File tree

4 files changed

+12
-31
lines changed

4 files changed

+12
-31
lines changed

library/proc_macro/src/bridge/client.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ macro_rules! define_client_handles {
2626
$(
2727
pub(crate) struct $oty {
2828
handle: handle::Handle,
29-
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
30-
// way of doing this, but that requires unstable features.
31-
// rust-analyzer uses this code and avoids unstable features.
32-
_marker: PhantomData<*mut ()>,
3329
}
3430

31+
impl !Send for $oty {}
32+
impl !Sync for $oty {}
33+
3534
// Forward `Drop::drop` to the inherent `drop` method.
3635
impl Drop for $oty {
3736
fn drop(&mut self) {
3837
$oty {
3938
handle: self.handle,
40-
_marker: PhantomData,
4139
}.drop();
4240
}
4341
}
@@ -64,7 +62,6 @@ macro_rules! define_client_handles {
6462
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
6563
$oty {
6664
handle: handle::Handle::decode(r, s),
67-
_marker: PhantomData,
6865
}
6966
}
7067
}
@@ -74,12 +71,11 @@ macro_rules! define_client_handles {
7471
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
7572
pub(crate) struct $ity {
7673
handle: handle::Handle,
77-
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
78-
// way of doing this, but that requires unstable features.
79-
// rust-analyzer uses this code and avoids unstable features.
80-
_marker: PhantomData<*mut ()>,
8174
}
8275

76+
impl !Send for $ity {}
77+
impl !Sync for $ity {}
78+
8379
impl<S> Encode<S> for $ity {
8480
fn encode(self, w: &mut Writer, s: &mut S) {
8581
self.handle.encode(w, s);
@@ -90,7 +86,6 @@ macro_rules! define_client_handles {
9086
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
9187
$ity {
9288
handle: handle::Handle::decode(r, s),
93-
_marker: PhantomData,
9489
}
9590
}
9691
}

library/proc_macro/src/bridge/closure.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::marker::PhantomData;
66
pub(super) struct Closure<'a, A, R> {
77
call: unsafe extern "C" fn(*mut Env, A) -> R,
88
env: *mut Env,
9-
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
10-
// this, but that requires unstable features. rust-analyzer uses this code
11-
// and avoids unstable features.
9+
// Prevent Send and Sync impls.
1210
//
1311
// The `'a` lifetime parameter represents the lifetime of `Env`.
1412
_marker: PhantomData<*mut &'a mut ()>,

library/proc_macro/src/bridge/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,11 @@ pub struct BridgeConfig<'a> {
160160

161161
/// If 'true', always invoke the default panic hook
162162
force_show_panics: bool,
163-
164-
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
165-
// this, but that requires unstable features. rust-analyzer uses this code
166-
// and avoids unstable features.
167-
_marker: marker::PhantomData<*mut ()>,
168163
}
169164

165+
impl !Send for BridgeConfig<'_> {}
166+
impl !Sync for BridgeConfig<'_> {}
167+
170168
#[forbid(unsafe_code)]
171169
#[allow(non_camel_case_types)]
172170
mod api_tags {

library/proc_macro/src/bridge/server.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,7 @@ impl ExecutionStrategy for SameThread {
295295

296296
let mut dispatch = |buf| dispatcher.dispatch(buf);
297297

298-
run_client(BridgeConfig {
299-
input,
300-
dispatch: (&mut dispatch).into(),
301-
force_show_panics,
302-
_marker: marker::PhantomData,
303-
})
298+
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
304299
}
305300
}
306301

@@ -331,12 +326,7 @@ where
331326
client.recv().expect("server died while client waiting for reply")
332327
};
333328

334-
run_client(BridgeConfig {
335-
input,
336-
dispatch: (&mut dispatch).into(),
337-
force_show_panics,
338-
_marker: marker::PhantomData,
339-
})
329+
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
340330
});
341331

342332
while let Some(b) = server.recv() {

0 commit comments

Comments
 (0)