about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-30 20:46:45 +0200
committerGitHub <noreply@github.com>2025-09-30 20:46:45 +0200
commit622ca20e78aa6bc3232f87fa3ccc0c97376d187f (patch)
tree6ad2215509166d22e4edcc44cb654e5a6cbf96b6
parentf7c7e34ae4b98edba4049326005c902fb7b6d0ab (diff)
parentd7773f6b1c220d43946bce8010847837ad334b74 (diff)
downloadrust-622ca20e78aa6bc3232f87fa3ccc0c97376d187f.tar.gz
rust-622ca20e78aa6bc3232f87fa3ccc0c97376d187f.zip
Rollup merge of #147166 - cyrgani:proc-macro-cleanup-1, r=petrochenkov
several small `proc_macro` cleanups
-rw-r--r--library/proc_macro/src/bridge/client.rs19
-rw-r--r--library/proc_macro/src/bridge/closure.rs4
-rw-r--r--library/proc_macro/src/bridge/mod.rs28
-rw-r--r--library/proc_macro/src/bridge/server.rs16
-rw-r--r--library/proc_macro/src/lib.rs1
5 files changed, 14 insertions, 54 deletions
diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs
index e7d547966a5..92558f2b7d9 100644
--- a/library/proc_macro/src/bridge/client.rs
+++ b/library/proc_macro/src/bridge/client.rs
@@ -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,
                     }
                 }
             }
@@ -144,7 +139,7 @@ macro_rules! define_client_side {
 
                     buf.clear();
                     api_tags::Method::$name(api_tags::$name::$method).encode(&mut buf, &mut ());
-                    reverse_encode!(buf; $($arg),*);
+                    $($arg.encode(&mut buf, &mut ());)*
 
                     buf = bridge.dispatch.call(buf);
 
diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/bridge/closure.rs
index e0e688434dc..e5133907854 100644
--- a/library/proc_macro/src/bridge/closure.rs
+++ b/library/proc_macro/src/bridge/closure.rs
@@ -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 ()>,
diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs
index d60a76fff5d..1b09deb6bfe 100644
--- a/library/proc_macro/src/bridge/mod.rs
+++ b/library/proc_macro/src/bridge/mod.rs
@@ -119,26 +119,6 @@ macro_rules! with_api_handle_types {
     };
 }
 
-// FIXME(eddyb) this calls `encode` for each argument, but in reverse,
-// to match the ordering in `reverse_decode`.
-macro_rules! reverse_encode {
-    ($writer:ident;) => {};
-    ($writer:ident; $first:ident $(, $rest:ident)*) => {
-        reverse_encode!($writer; $($rest),*);
-        $first.encode(&mut $writer, &mut ());
-    }
-}
-
-// FIXME(eddyb) this calls `decode` for each argument, but in reverse,
-// to avoid borrow conflicts from borrows started by `&mut` arguments.
-macro_rules! reverse_decode {
-    ($reader:ident, $s:ident;) => {};
-    ($reader:ident, $s:ident; $first:ident: $first_ty:ty $(, $rest:ident: $rest_ty:ty)*) => {
-        reverse_decode!($reader, $s; $($rest: $rest_ty),*);
-        let $first = <$first_ty>::decode(&mut $reader, $s);
-    }
-}
-
 #[allow(unsafe_code)]
 mod arena;
 #[allow(unsafe_code)]
@@ -180,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 {
diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs
index 5beda7c3c96..0bb30698aa1 100644
--- a/library/proc_macro/src/bridge/server.rs
+++ b/library/proc_macro/src/bridge/server.rs
@@ -178,7 +178,7 @@ macro_rules! define_dispatcher_impl {
                     $(api_tags::Method::$name(m) => match m {
                         $(api_tags::$name::$method => {
                             let mut call_method = || {
-                                reverse_decode!(reader, handle_store; $($arg: $arg_ty),*);
+                                $(let $arg = <$arg_ty>::decode(&mut reader, handle_store);)*
                                 $name::$method(server, $($arg),*)
                             };
                             // HACK(eddyb) don't use `panic::catch_unwind` in a panic.
@@ -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() {
diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs
index 162b4fdcc8a..613abd7024e 100644
--- a/library/proc_macro/src/lib.rs
+++ b/library/proc_macro/src/lib.rs
@@ -27,7 +27,6 @@
 #![feature(panic_can_unwind)]
 #![feature(restricted_std)]
 #![feature(rustc_attrs)]
-#![feature(stmt_expr_attributes)]
 #![feature(extend_one)]
 #![recursion_limit = "256"]
 #![allow(internal_features)]