Skip to content

Commit

Permalink
Work-around for shadowing of variant names with assoc const names in …
Browse files Browse the repository at this point in the history
…`libproc_macro/bridge/rpc.rs`.
  • Loading branch information
Alexander Regueiro committed Dec 26, 2018
1 parent 6a2a7ed commit edabad6
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/libproc_macro/bridge/rpc.rs
Expand Up @@ -71,15 +71,18 @@ macro_rules! rpc_encode_decode {
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
fn encode(self, w: &mut Writer, s: &mut S) {
// HACK(eddyb) `Tag` enum duplicated between the
// HACK(eddyb): `Tag` enum duplicated between the
// two impls as there's no other place to stash it.
#[repr(u8)] enum Tag { $($variant),* }
#[allow(non_upper_case_globals)]
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
mod tag {
#[repr(u8)] enum Tag { $($variant),* }

$(pub const $variant: u8 = Tag::$variant as u8;)*
}

match self {
$($name::$variant $(($field))* => {
<Tag>::$variant.encode(w, s);
tag::$variant.encode(w, s);
$($field.encode(w, s);)*
})*
}
Expand All @@ -90,14 +93,17 @@ macro_rules! rpc_encode_decode {
for $name $(<$($T),+>)*
{
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
// HACK(eddyb) `Tag` enum duplicated between the
// HACK(eddyb): `Tag` enum duplicated between the
// two impls as there's no other place to stash it.
#[repr(u8)] enum Tag { $($variant),* }
#[allow(non_upper_case_globals)]
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
mod tag {
#[repr(u8)] enum Tag { $($variant),* }

$(pub const $variant: u8 = Tag::$variant as u8;)*
}

match u8::decode(r, s) {
$(<Tag>::$variant => {
$(tag::$variant => {
$(let $field = DecodeMut::decode(r, s);)*
$name::$variant $(($field))*
})*
Expand Down

0 comments on commit edabad6

Please sign in to comment.