Skip to content

Commit 428be2f

Browse files
authored
Rollup merge of #147497 - cyrgani:proc-macro-cleanups-3, r=petrochenkov
`proc_macro` cleanups (3/N) Followup to #147386, which removed the old `Decode` trait. Can be reviewed commit by commit.
2 parents 4321adf + 6a12470 commit 428be2f

6 files changed

Lines changed: 33 additions & 38 deletions

File tree

‎library/proc_macro/src/bridge/client.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! define_client_handles {
5858
}
5959
}
6060

61-
impl<S> DecodeMut<'_,'_,S> for $oty {
61+
impl<S> Decode<'_,'_,S> for $oty {
6262
fn decode(r:&mutReader<'_>, s:&mutS) -> Self{
6363
$oty {
6464
handle: handle::Handle::decode(r, s),
@@ -82,7 +82,7 @@ macro_rules! define_client_handles {
8282
}
8383
}
8484

85-
impl<S> DecodeMut<'_,'_,S> for $ity {
85+
impl<S> Decode<'_,'_,S> for $ity {
8686
fn decode(r:&mutReader<'_>, s:&mutS) -> Self{
8787
$ity {
8888
handle: handle::Handle::decode(r, s),
@@ -276,7 +276,7 @@ fn maybe_install_panic_hook(force_show_panics: bool) {
276276
/// Client-side helper for handling client panics, entering the bridge,
277277
/// deserializing input and serializing output.
278278
// FIXME(eddyb) maybe replace `Bridge::enter` with this?
279-
fnrun_client<A:for<'a,'s>DecodeMut<'a,'s,()>,R:Encode<()>>(
279+
fnrun_client<A:for<'a,'s>Decode<'a,'s,()>,R:Encode<()>>(
280280
config:BridgeConfig<'_>,
281281
f:implFnOnce(A) -> R,
282282
) -> Buffer{

‎library/proc_macro/src/bridge/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mod symbol;
143143

144144
use buffer::Buffer;
145145
pubuse rpc::PanicMessage;
146-
use rpc::{DecodeMut,Encode,Reader,Writer};
146+
use rpc::{Decode,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`),
@@ -168,7 +168,7 @@ impl !Sync for BridgeConfig<'_> {}
168168
#[forbid(unsafe_code)]
169169
#[allow(non_camel_case_types)]
170170
mod api_tags {
171-
usesuper::rpc::{DecodeMut,Encode,Reader,Writer};
171+
usesuper::rpc::{Decode,Encode,Reader,Writer};
172172

173173
macro_rules! declare_tags {
174174
($($name:ident {

‎library/proc_macro/src/bridge/rpc.rs‎

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(super) trait Encode<S>: Sized {
1212

1313
pub(super)typeReader<'a> = &'a[u8];
1414

15-
pub(super)traitDecodeMut<'a,'s,S>:Sized{
15+
pub(super)traitDecode<'a,'s,S>:Sized{
1616
fndecode(r:&mutReader<'a>,s:&'smutS) -> Self;
1717
}
1818

@@ -24,7 +24,7 @@ macro_rules! rpc_encode_decode {
2424
}
2525
}
2626

27-
impl<S> DecodeMut<'_,'_,S> for $ty {
27+
impl<S> Decode<'_,'_,S> for $ty {
2828
fn decode(r:&mutReader<'_>, _:&mutS) -> Self{
2929
constN:usize = size_of::<$ty>();
3030

@@ -43,12 +43,12 @@ macro_rules! rpc_encode_decode {
4343
}
4444
}
4545

46-
impl<'a,S, $($($T:for<'s> DecodeMut<'a,'s,S>),+)?> DecodeMut<'a,'_,S>
46+
impl<'a,S, $($($T:for<'s> Decode<'a,'s,S>),+)?> Decode<'a,'_,S>
4747
for $name $(<$($T),+>)?
4848
{
4949
fn decode(r:&mutReader<'a>, s:&mutS) -> Self{
5050
$name {
51-
$($field:DecodeMut::decode(r, s)),*
51+
$($field:Decode::decode(r, s)),*
5252
}
5353
}
5454
}
@@ -58,23 +58,18 @@ macro_rules! rpc_encode_decode {
5858
fn encode(self, w:&mutWriter, s:&mutS){
5959
// HACK(eddyb): `Tag` enum duplicated between the
6060
// two impls as there's no other place to stash it.
61-
#[allow(non_upper_case_globals)]
62-
mod tag {
63-
#[repr(u8)]enumTag{ $($variant),*}
64-
65-
$(pub(crate)const $variant:u8 = Tag::$variant asu8;)*
66-
}
61+
#[repr(u8)]enumTag{ $($variant),*}
6762

6863
matchself{
6964
$($name::$variant $(($field))* => {
70-
tag::$variant.encode(w, s);
65+
(Tag::$variantasu8).encode(w, s);
7166
$($field.encode(w, s);)*
7267
})*
7368
}
7469
}
7570
}
7671

77-
impl<'a,S, $($($T:for<'s> DecodeMut<'a,'s,S>),+)?> DecodeMut<'a,'_,S>
72+
impl<'a,S, $($($T:for<'s> Decode<'a,'s,S>),+)?> Decode<'a,'_,S>
7873
for $name $(<$($T),+>)?
7974
{
8075
fn decode(r:&mutReader<'a>, s:&mutS) -> Self{
@@ -89,7 +84,7 @@ macro_rules! rpc_encode_decode {
8984

9085
matchu8::decode(r, s){
9186
$(tag::$variant => {
92-
$(let $field = DecodeMut::decode(r, s);)*
87+
$(let $field = Decode::decode(r, s);)*
9388
$name::$variant $(($field))*
9489
})*
9590
_ => unreachable!(),
@@ -103,7 +98,7 @@ impl<S> Encode<S> for () {
10398
fnencode(self, _:&mutWriter, _:&mutS){}
10499
}
105100

106-
impl<S>DecodeMut<'_,'_,S>for(){
101+
impl<S>Decode<'_,'_,S>for(){
107102
fndecode(_:&mutReader<'_>, _:&mutS) -> Self{}
108103
}
109104

@@ -113,7 +108,7 @@ impl<S> Encode<S> for u8 {
113108
}
114109
}
115110

116-
impl<S>DecodeMut<'_,'_,S>foru8{
111+
impl<S>Decode<'_,'_,S>foru8{
117112
fndecode(r:&mutReader<'_>, _:&mutS) -> Self{
118113
let x = r[0];
119114
*r = &r[1..];
@@ -130,7 +125,7 @@ impl<S> Encode<S> for bool {
130125
}
131126
}
132127

133-
impl<S>DecodeMut<'_,'_,S>forbool{
128+
impl<S>Decode<'_,'_,S>forbool{
134129
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
135130
match u8::decode(r, s){
136131
0 => false,
@@ -146,7 +141,7 @@ impl<S> Encode<S> for char {
146141
}
147142
}
148143

149-
impl<S>DecodeMut<'_,'_,S>forchar{
144+
impl<S>Decode<'_,'_,S>forchar{
150145
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
151146
char::from_u32(u32::decode(r, s)).unwrap()
152147
}
@@ -158,7 +153,7 @@ impl<S> Encode<S> for NonZero<u32> {
158153
}
159154
}
160155

161-
impl<S>DecodeMut<'_,'_,S>forNonZero<u32>{
156+
impl<S>Decode<'_,'_,S>forNonZero<u32>{
162157
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
163158
Self::new(u32::decode(r, s)).unwrap()
164159
}
@@ -171,11 +166,11 @@ impl<S, A: Encode<S>, B: Encode<S>> Encode<S> for (A, B) {
171166
}
172167
}
173168

174-
impl<'a,S,A:for<'s>DecodeMut<'a,'s,S>,B:for<'s>DecodeMut<'a,'s,S>>DecodeMut<'a,'_,S>
169+
impl<'a,S,A:for<'s>Decode<'a,'s,S>,B:for<'s>Decode<'a,'s,S>>Decode<'a,'_,S>
175170
for(A,B)
176171
{
177172
fndecode(r:&mutReader<'a>,s:&mutS) -> Self{
178-
(DecodeMut::decode(r, s),DecodeMut::decode(r, s))
173+
(Decode::decode(r, s),Decode::decode(r, s))
179174
}
180175
}
181176

@@ -186,7 +181,7 @@ impl<S> Encode<S> for &[u8] {
186181
}
187182
}
188183

189-
impl<'a,S>DecodeMut<'a,'_,S>for&'a[u8]{
184+
impl<'a,S>Decode<'a,'_,S>for&'a[u8]{
190185
fndecode(r:&mutReader<'a>,s:&mutS) -> Self{
191186
let len = usize::decode(r, s);
192187
let xs = &r[..len];
@@ -201,7 +196,7 @@ impl<S> Encode<S> for &str {
201196
}
202197
}
203198

204-
impl<'a,S>DecodeMut<'a,'_,S>for&'astr{
199+
impl<'a,S>Decode<'a,'_,S>for&'astr{
205200
fndecode(r:&mutReader<'a>,s:&mutS) -> Self{
206201
str::from_utf8(<&[u8]>::decode(r, s)).unwrap()
207202
}
@@ -213,7 +208,7 @@ impl<S> Encode<S> for String {
213208
}
214209
}
215210

216-
impl<S>DecodeMut<'_,'_,S>forString{
211+
impl<S>Decode<'_,'_,S>forString{
217212
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
218213
<&str>::decode(r, s).to_string()
219214
}
@@ -228,7 +223,7 @@ impl<S, T: Encode<S>> Encode<S> for Vec<T> {
228223
}
229224
}
230225

231-
impl<'a,S,T:for<'s>DecodeMut<'a,'s,S>>DecodeMut<'a,'_,S>forVec<T>{
226+
impl<'a,S,T:for<'s>Decode<'a,'s,S>>Decode<'a,'_,S>forVec<T>{
232227
fndecode(r:&mutReader<'a>,s:&mutS) -> Self{
233228
let len = usize::decode(r, s);
234229
letmut vec = Vec::with_capacity(len);
@@ -288,7 +283,7 @@ impl<S> Encode<S> for PanicMessage {
288283
}
289284
}
290285

291-
impl<S>DecodeMut<'_,'_,S>forPanicMessage{
286+
impl<S>Decode<'_,'_,S>forPanicMessage{
292287
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
293288
matchOption::<String>::decode(r, s){
294289
Some(s) => PanicMessage::String(s),

‎library/proc_macro/src/bridge/selfless_reify.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! define_reify_functions {
5050
>(f:F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty {
5151
// FIXME(eddyb) describe the `F` type (e.g. via `type_name::<F>`) once panic
5252
// formatting becomes possible in `const fn`.
53-
assert!(size_of::<F>() == 0,"selfless_reify: closure must be zero-sized");
53+
const{assert!(size_of::<F>() == 0,"selfless_reify: closure must be zero-sized");}
5454

5555
$(extern $abi)? fn wrapper<
5656
$($($param,)*)?

‎library/proc_macro/src/bridge/server.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ macro_rules! define_server_handles {
3232
}
3333
}
3434

35-
impl<S:Types> DecodeMut<'_,'_,HandleStore<MarkedTypes<S>>>
35+
impl<S:Types> Decode<'_,'_,HandleStore<MarkedTypes<S>>>
3636
forMarked<S::$oty, client::$oty>
3737
{
3838
fn decode(r:&mutReader<'_>, s:&mutHandleStore<MarkedTypes<S>>) -> Self{
3939
s.$oty.take(handle::Handle::decode(r,&mut()))
4040
}
4141
}
4242

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

51-
impl<'s,S:Types> DecodeMut<'_,'s,HandleStore<MarkedTypes<S>>>
51+
impl<'s,S:Types> Decode<'_,'s,HandleStore<MarkedTypes<S>>>
5252
for&'s mutMarked<S::$oty, client::$oty>
5353
{
5454
fn decode(
@@ -67,7 +67,7 @@ macro_rules! define_server_handles {
6767
}
6868
}
6969

70-
impl<S:Types> DecodeMut<'_,'_,HandleStore<MarkedTypes<S>>>
70+
impl<S:Types> Decode<'_,'_,HandleStore<MarkedTypes<S>>>
7171
forMarked<S::$ity, client::$ity>
7272
{
7373
fn decode(r:&mutReader<'_>, s:&mutHandleStore<MarkedTypes<S>>) -> Self{
@@ -355,7 +355,7 @@ pub trait MessagePipe<T>: Sized {
355355
fnrun_server<
356356
S:Server,
357357
I:Encode<HandleStore<MarkedTypes<S>>>,
358-
O:for<'a,'s>DecodeMut<'a,'s,HandleStore<MarkedTypes<S>>>,
358+
O:for<'a,'s>Decode<'a,'s,HandleStore<MarkedTypes<S>>>,
359359
>(
360360
strategy:&implExecutionStrategy,
361361
handle_counters:&'static client::HandleCounters,

‎library/proc_macro/src/bridge/symbol.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<S> Encode<S> for Symbol {
102102
}
103103
}
104104

105-
impl<S: server::Server>DecodeMut<'_,'_, server::HandleStore<server::MarkedTypes<S>>>
105+
impl<S: server::Server>Decode<'_,'_, server::HandleStore<server::MarkedTypes<S>>>
106106
forMarked<S::Symbol,Symbol>
107107
{
108108
fndecode(r:&mutReader<'_>,s:&mut server::HandleStore<server::MarkedTypes<S>>) -> Self{
@@ -118,7 +118,7 @@ impl<S: server::Server> Encode<server::HandleStore<server::MarkedTypes<S>>>
118118
}
119119
}
120120

121-
impl<S>DecodeMut<'_,'_,S>forSymbol{
121+
impl<S>Decode<'_,'_,S>forSymbol{
122122
fndecode(r:&mutReader<'_>,s:&mutS) -> Self{
123123
Symbol::new(<&str>::decode(r, s))
124124
}

0 commit comments

Comments
 (0)