Skip to content

Commit

Permalink
Use PhantomData directly in Bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Apr 6, 2022
1 parent 6eab980 commit 7eda975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
/// then passes it to the client through the function pointer in the `run`
/// field of `client::Client`. The client holds its copy of the `Bridge`
/// in TLS during its execution (`Bridge::{enter, with}` in `client.rs`).
// Note: Bridge is !Send and !Sync due to containg a `Closure`. If this
// ever changes, make sure to preserve the !Send and !Sync property.
#[repr(C)]
pub struct Bridge<'a> {
/// Reusable buffer (only `clear`-ed, never shrunk), primarily
Expand All @@ -233,6 +231,9 @@ pub struct Bridge<'a> {

/// If 'true', always invoke the default panic hook
force_show_panics: bool,

// Prevent Send and Sync impls
_marker: marker::PhantomData<*mut ()>,
}

#[forbid(unsafe_code)]
Expand Down
9 changes: 8 additions & 1 deletion library/proc_macro/src/bridge/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ impl ExecutionStrategy for SameThread {
let mut dispatch = |b| dispatcher.dispatch(b);

run_client(
Bridge { cached_buffer: input, dispatch: (&mut dispatch).into(), force_show_panics },
Bridge {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
)
}
Expand Down Expand Up @@ -189,6 +194,7 @@ impl ExecutionStrategy for CrossThread1 {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
)
Expand Down Expand Up @@ -241,6 +247,7 @@ impl ExecutionStrategy for CrossThread2 {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
);
Expand Down

0 comments on commit 7eda975

Please sign in to comment.