From 0a6462be908f00555dd7fadc6c7ed2fa751856ee Mon Sep 17 00:00:00 2001 From: cyrgani Date: Sun, 5 Oct 2025 23:25:08 +0200 Subject: [PATCH 1/3] remove unneeded imports --- library/proc_macro/src/bridge/arena.rs | 2 +- library/proc_macro/src/bridge/rpc.rs | 3 +-- library/proc_macro/src/bridge/symbol.rs | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/library/proc_macro/src/bridge/arena.rs b/library/proc_macro/src/bridge/arena.rs index bf5a5b5a81821..dee4e7b976de6 100644 --- a/library/proc_macro/src/bridge/arena.rs +++ b/library/proc_macro/src/bridge/arena.rs @@ -7,7 +7,7 @@ use std::cell::{Cell, RefCell}; use std::mem::MaybeUninit; use std::ops::Range; -use std::{cmp, ptr, slice, str}; +use std::{cmp, ptr, slice}; // The arenas start with PAGE-sized chunks, and then each new chunk is twice as // big as its predecessor, up until we reach HUGE_PAGE-sized chunks, whereupon diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 85fd7d138585c..26ea42b49b7f8 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -3,7 +3,6 @@ use std::any::Any; use std::io::Write; use std::num::NonZero; -use std::str; pub(super) type Writer = super::buffer::Buffer; @@ -31,7 +30,7 @@ macro_rules! rpc_encode_decode { impl DecodeMut<'_, '_, S> for $ty { fn decode(r: &mut Reader<'_>, _: &mut S) -> Self { - const N: usize = ::std::mem::size_of::<$ty>(); + const N: usize = size_of::<$ty>(); let mut bytes = [0; N]; bytes.copy_from_slice(&r[..N]); diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/bridge/symbol.rs index 57ca7db9fcdd7..eb7d30f9a6cc9 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/bridge/symbol.rs @@ -11,7 +11,6 @@ use std::cell::RefCell; use std::num::NonZero; -use std::str; use super::*; From 74ec42e000d8385343a7b0ea96f28ed4371d4235 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 7 Oct 2025 21:21:07 +0200 Subject: [PATCH 2/3] refactor confusing loop in `proc_macro` arena --- library/proc_macro/src/bridge/arena.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library/proc_macro/src/bridge/arena.rs b/library/proc_macro/src/bridge/arena.rs index dee4e7b976de6..5e0393e98fdd2 100644 --- a/library/proc_macro/src/bridge/arena.rs +++ b/library/proc_macro/src/bridge/arena.rs @@ -90,14 +90,13 @@ impl Arena { return &mut []; } - loop { - if let Some(a) = self.alloc_raw_without_grow(bytes) { - break a; - } - // No free space left. Allocate a new chunk to satisfy the request. - // On failure the grow will panic or abort. - self.grow(bytes); + if let Some(a) = self.alloc_raw_without_grow(bytes) { + return a; } + // No free space left. Allocate a new chunk to satisfy the request. + // On failure the grow will panic or abort. + self.grow(bytes); + self.alloc_raw_without_grow(bytes).unwrap() } #[allow(clippy::mut_from_ref)] // arena allocator From 7aa52ea97afe436b013f6276f1d9a866fb027846 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 7 Oct 2025 21:21:40 +0200 Subject: [PATCH 3/3] remove `Decode` trait and only impl --- library/proc_macro/src/bridge/mod.rs | 2 +- library/proc_macro/src/bridge/rpc.rs | 4 ---- library/proc_macro/src/bridge/server.rs | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index 1b09deb6bfe60..582c43c78fcbb 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -143,7 +143,7 @@ mod symbol; use buffer::Buffer; pub use rpc::PanicMessage; -use rpc::{Decode, DecodeMut, Encode, Reader, Writer}; +use rpc::{DecodeMut, Encode, Reader, Writer}; /// Configuration for establishing an active connection between a server and a /// client. The server creates the bridge config (`run_server` in `server.rs`), diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 26ea42b49b7f8..7f4f5fc3a97d5 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -12,10 +12,6 @@ pub(super) trait Encode: Sized { pub(super) type Reader<'a> = &'a [u8]; -pub(super) trait Decode<'a, 's, S>: Sized { - fn decode(r: &mut Reader<'a>, s: &'s S) -> Self; -} - pub(super) trait DecodeMut<'a, 's, S>: Sized { fn decode(r: &mut Reader<'a>, s: &'s mut S) -> Self; } diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs index 0bb30698aa1d7..2850e1099b700 100644 --- a/library/proc_macro/src/bridge/server.rs +++ b/library/proc_macro/src/bridge/server.rs @@ -40,10 +40,10 @@ macro_rules! define_server_handles { } } - impl<'s, S: Types> Decode<'_, 's, HandleStore>> + impl<'s, S: Types> DecodeMut<'_, 's, HandleStore>> for &'s Marked { - fn decode(r: &mut Reader<'_>, s: &'s HandleStore>) -> Self { + fn decode(r: &mut Reader<'_>, s: &'s mut HandleStore>) -> Self { &s.$oty[handle::Handle::decode(r, &mut ())] } }