Skip to content

Commit 79305cf

Browse files
author
Alexander Regueiro
committed
Work-around for shadowing of variant names with assoc const names in libproc_macro/bridge/rpc.rs.
1 parent a65b5d8 commit 79305cf

File tree

1 file changed

+14
-8
lines changed
  • src/libproc_macro/bridge

1 file changed

+14
-8
lines changed

src/libproc_macro/bridge/rpc.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ macro_rules! rpc_encode_decode {
8181
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
8282
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
8383
fn encode(self, w: &mut Writer, s: &mut S) {
84-
// HACK(eddyb) `Tag` enum duplicated between the
84+
// HACK(eddyb): `Tag` enum duplicated between the
8585
// two impls as there's no other place to stash it.
86-
#[repr(u8)] enum Tag { $($variant),* }
8786
#[allow(non_upper_case_globals)]
88-
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
87+
mod tag {
88+
#[repr(u8)] enum Tag { $($variant),* }
89+
90+
$(pub const $variant: u8 = Tag::$variant as u8;)*
91+
}
8992

9093
match self {
9194
$($name::$variant $(($field))* => {
92-
<Tag>::$variant.encode(w, s);
95+
tag::$variant.encode(w, s);
9396
$($field.encode(w, s);)*
9497
})*
9598
}
@@ -100,14 +103,17 @@ macro_rules! rpc_encode_decode {
100103
for $name $(<$($T),+>)*
101104
{
102105
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
103-
// HACK(eddyb) `Tag` enum duplicated between the
106+
// HACK(eddyb): `Tag` enum duplicated between the
104107
// two impls as there's no other place to stash it.
105-
#[repr(u8)] enum Tag { $($variant),* }
106108
#[allow(non_upper_case_globals)]
107-
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
109+
mod tag {
110+
#[repr(u8)] enum Tag { $($variant),* }
111+
112+
$(pub const $variant: u8 = Tag::$variant as u8;)*
113+
}
108114

109115
match u8::decode(r, s) {
110-
$(<Tag>::$variant => {
116+
$(tag::$variant => {
111117
$(let $field = DecodeMut::decode(r, s);)*
112118
$name::$variant $(($field))*
113119
})*

0 commit comments

Comments
 (0)