Skip to content

Commit 5c13022

Browse files
authored
Rollup merge of #147386 - cyrgani:proc-macro-cleanup-2, r=petrochenkov
some more `proc_macro` cleanups Several smaller cleanups to `proc_macro`. Commits 1 and 3 seem pretty trivial to me, commit 2 might be worth it or not. Followup to #147166.
2 parents 193a28d + 7aa52ea commit 5c13022

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

library/proc_macro/src/bridge/arena.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use std::cell::{Cell, RefCell};
88
use std::mem::MaybeUninit;
99
use std::ops::Range;
10-
use std::{cmp, ptr, slice, str};
10+
use std::{cmp, ptr, slice};
1111

1212
// The arenas start with PAGE-sized chunks, and then each new chunk is twice as
1313
// big as its predecessor, up until we reach HUGE_PAGE-sized chunks, whereupon
@@ -90,14 +90,13 @@ impl Arena {
9090
return &mut [];
9191
}
9292

93-
loop {
94-
if let Some(a) = self.alloc_raw_without_grow(bytes) {
95-
break a;
96-
}
97-
// No free space left. Allocate a new chunk to satisfy the request.
98-
// On failure the grow will panic or abort.
99-
self.grow(bytes);
93+
if let Some(a) = self.alloc_raw_without_grow(bytes) {
94+
return a;
10095
}
96+
// No free space left. Allocate a new chunk to satisfy the request.
97+
// On failure the grow will panic or abort.
98+
self.grow(bytes);
99+
self.alloc_raw_without_grow(bytes).unwrap()
101100
}
102101

103102
#[allow(clippy::mut_from_ref)] // arena allocator

library/proc_macro/src/bridge/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mod symbol;
143143

144144
use buffer::Buffer;
145145
pub use rpc::PanicMessage;
146-
use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
146+
use rpc::{DecodeMut, Encode, Reader, Writer};
147147

148148
/// Configuration for establishing an active connection between a server and a
149149
/// client. The server creates the bridge config (`run_server` in `server.rs`),

library/proc_macro/src/bridge/rpc.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::any::Any;
44
use std::io::Write;
55
use std::num::NonZero;
6-
use std::str;
76

87
pub(super) type Writer = super::buffer::Buffer;
98

@@ -13,10 +12,6 @@ pub(super) trait Encode<S>: Sized {
1312

1413
pub(super) type Reader<'a> = &'a [u8];
1514

16-
pub(super) trait Decode<'a, 's, S>: Sized {
17-
fn decode(r: &mut Reader<'a>, s: &'s S) -> Self;
18-
}
19-
2015
pub(super) trait DecodeMut<'a, 's, S>: Sized {
2116
fn decode(r: &mut Reader<'a>, s: &'s mut S) -> Self;
2217
}
@@ -31,7 +26,7 @@ macro_rules! rpc_encode_decode {
3126

3227
impl<S> DecodeMut<'_, '_, S> for $ty {
3328
fn decode(r: &mut Reader<'_>, _: &mut S) -> Self {
34-
const N: usize = ::std::mem::size_of::<$ty>();
29+
const N: usize = size_of::<$ty>();
3530

3631
let mut bytes = [0; N];
3732
bytes.copy_from_slice(&r[..N]);

library/proc_macro/src/bridge/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ macro_rules! define_server_handles {
4040
}
4141
}
4242

43-
impl<'s, S: Types> Decode<'_, 's, HandleStore<MarkedTypes<S>>>
43+
impl<'s, S: Types> DecodeMut<'_, 's, HandleStore<MarkedTypes<S>>>
4444
for &'s Marked<S::$oty, client::$oty>
4545
{
46-
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<MarkedTypes<S>>) -> Self {
46+
fn decode(r: &mut Reader<'_>, s: &'s mut HandleStore<MarkedTypes<S>>) -> Self {
4747
&s.$oty[handle::Handle::decode(r, &mut ())]
4848
}
4949
}

library/proc_macro/src/bridge/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
use std::cell::RefCell;
1313
use std::num::NonZero;
14-
use std::str;
1514

1615
use super::*;
1716

0 commit comments

Comments
 (0)