Skip to content

Commit edabad6

Browse files
committed
Work-around for shadowing of variant names with assoc const names in libproc_macro/bridge/rpc.rs.
1 parent 6a2a7ed commit edabad6

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,18 @@ macro_rules! rpc_encode_decode {
7171
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
7272
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
7373
fn encode(self, w: &mut Writer, s: &mut S) {
74-
// HACK(eddyb) `Tag` enum duplicated between the
74+
// HACK(eddyb): `Tag` enum duplicated between the
7575
// two impls as there's no other place to stash it.
76-
#[repr(u8)] enum Tag { $($variant),* }
7776
#[allow(non_upper_case_globals)]
78-
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
77+
mod tag {
78+
#[repr(u8)] enum Tag { $($variant),* }
79+
80+
$(pub const $variant: u8 = Tag::$variant as u8;)*
81+
}
7982

8083
match self {
8184
$($name::$variant $(($field))* => {
82-
<Tag>::$variant.encode(w, s);
85+
tag::$variant.encode(w, s);
8386
$($field.encode(w, s);)*
8487
})*
8588
}
@@ -90,14 +93,17 @@ macro_rules! rpc_encode_decode {
9093
for $name $(<$($T),+>)*
9194
{
9295
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
93-
// HACK(eddyb) `Tag` enum duplicated between the
96+
// HACK(eddyb): `Tag` enum duplicated between the
9497
// two impls as there's no other place to stash it.
95-
#[repr(u8)] enum Tag { $($variant),* }
9698
#[allow(non_upper_case_globals)]
97-
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
99+
mod tag {
100+
#[repr(u8)] enum Tag { $($variant),* }
101+
102+
$(pub const $variant: u8 = Tag::$variant as u8;)*
103+
}
98104

99105
match u8::decode(r, s) {
100-
$(<Tag>::$variant => {
106+
$(tag::$variant => {
101107
$(let $field = DecodeMut::decode(r, s);)*
102108
$name::$variant $(($field))*
103109
})*

0 commit comments

Comments
 (0)