about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2022-04-06 18:53:19 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2022-04-06 18:53:19 +0200
commit7eda975b06a0896139e6ab0d23df22c6d357e146 (patch)
tree53e8389039fb1f3dfef90d54f04fb0f4219485f8
parent6eab9802c9d43cc7b2340fd93c49881850cd3b20 (diff)
downloadrust-7eda975b06a0896139e6ab0d23df22c6d357e146.tar.gz
rust-7eda975b06a0896139e6ab0d23df22c6d357e146.zip
Use PhantomData directly in Bridge
-rw-r--r--library/proc_macro/src/bridge/mod.rs5
-rw-r--r--library/proc_macro/src/bridge/server.rs9
2 files changed, 11 insertions, 3 deletions
diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs
index d1f7d84991d..f7c9df6564f 100644
--- a/library/proc_macro/src/bridge/mod.rs
+++ b/library/proc_macro/src/bridge/mod.rs
@@ -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
@@ -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)]
diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs
index 1b3ccf4c18e..2e0400d32a0 100644
--- a/library/proc_macro/src/bridge/server.rs
+++ b/library/proc_macro/src/bridge/server.rs
@@ -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,
         )
     }
@@ -189,6 +194,7 @@ impl ExecutionStrategy for CrossThread1 {
                     cached_buffer: input,
                     dispatch: (&mut dispatch).into(),
                     force_show_panics,
+                    _marker: marker::PhantomData,
                 },
                 client_data,
             )
@@ -241,6 +247,7 @@ impl ExecutionStrategy for CrossThread2 {
                     cached_buffer: input,
                     dispatch: (&mut dispatch).into(),
                     force_show_panics,
+                    _marker: marker::PhantomData,
                 },
                 client_data,
             );