Rollup merge of #152531 - cyrgani:pm-yet-another-cleanup, r=petrochenkov

`proc_macro::bridge`: simplify `ExecutionStrategy` and `DispatcherTrait`

Also includes another tiny cleanup (functions can only have one return type).
This commit is contained in:
Jonathan Brouwer 2026-02-14 18:55:36 +01:00 committed by GitHub
commit 8a03b5f3ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 68 additions and 124 deletions

View file

@ -11,32 +11,11 @@ use {rustc_ast as ast, rustc_proc_macro as pm};
use crate::base::{self, *};
use crate::{errors, proc_macro_server};
struct MessagePipe<T> {
tx: std::sync::mpsc::SyncSender<T>,
rx: std::sync::mpsc::Receiver<T>,
}
impl<T> pm::bridge::server::MessagePipe<T> for MessagePipe<T> {
fn new() -> (Self, Self) {
let (tx1, rx1) = std::sync::mpsc::sync_channel(1);
let (tx2, rx2) = std::sync::mpsc::sync_channel(1);
(MessagePipe { tx: tx1, rx: rx2 }, MessagePipe { tx: tx2, rx: rx1 })
}
fn send(&mut self, value: T) {
self.tx.send(value).unwrap();
}
fn recv(&mut self) -> Option<T> {
self.rx.recv().ok()
}
}
fn exec_strategy(sess: &Session) -> impl pm::bridge::server::ExecutionStrategy + 'static {
pm::bridge::server::MaybeCrossThread::<MessagePipe<_>>::new(
sess.opts.unstable_opts.proc_macro_execution_strategy
pm::bridge::server::MaybeCrossThread {
cross_thread: sess.opts.unstable_opts.proc_macro_execution_strategy
== ProcMacroExecutionStrategy::CrossThread,
)
}
}
pub struct BangProcMacro {