Skip to content

Commit 7eda975

Browse files
committed
Use PhantomData directly in Bridge
1 parent 6eab980 commit 7eda975

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

library/proc_macro/src/bridge/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
220220
/// then passes it to the client through the function pointer in the `run`
221221
/// field of `client::Client`. The client holds its copy of the `Bridge`
222222
/// in TLS during its execution (`Bridge::{enter, with}` in `client.rs`).
223-
// Note: Bridge is !Send and !Sync due to containg a `Closure`. If this
224-
// ever changes, make sure to preserve the !Send and !Sync property.
225223
#[repr(C)]
226224
pub struct Bridge<'a> {
227225
/// Reusable buffer (only `clear`-ed, never shrunk), primarily
@@ -233,6 +231,9 @@ pub struct Bridge<'a> {
233231

234232
/// If 'true', always invoke the default panic hook
235233
force_show_panics: bool,
234+
235+
// Prevent Send and Sync impls
236+
_marker: marker::PhantomData<*mut ()>,
236237
}
237238

238239
#[forbid(unsafe_code)]

library/proc_macro/src/bridge/server.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ impl ExecutionStrategy for SameThread {
153153
let mut dispatch = |b| dispatcher.dispatch(b);
154154

155155
run_client(
156-
Bridge { cached_buffer: input, dispatch: (&mut dispatch).into(), force_show_panics },
156+
Bridge {
157+
cached_buffer: input,
158+
dispatch: (&mut dispatch).into(),
159+
force_show_panics,
160+
_marker: marker::PhantomData,
161+
},
157162
client_data,
158163
)
159164
}
@@ -189,6 +194,7 @@ impl ExecutionStrategy for CrossThread1 {
189194
cached_buffer: input,
190195
dispatch: (&mut dispatch).into(),
191196
force_show_panics,
197+
_marker: marker::PhantomData,
192198
},
193199
client_data,
194200
)
@@ -241,6 +247,7 @@ impl ExecutionStrategy for CrossThread2 {
241247
cached_buffer: input,
242248
dispatch: (&mut dispatch).into(),
243249
force_show_panics,
250+
_marker: marker::PhantomData,
244251
},
245252
client_data,
246253
);

0 commit comments

Comments
 (0)