Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode derive macro breaks when inside macro #557

Open
AlexApps99 opened this issue Jun 21, 2022 · 1 comment
Open

Encode derive macro breaks when inside macro #557

AlexApps99 opened this issue Jun 21, 2022 · 1 comment

Comments

@AlexApps99
Copy link

error[E0425]: cannot find value `field_0` in this scope
  --> bug/src/lib.rs:4:29
   |
1  | / macro_rules! dv {
2  | |     ($($t:item),+) => {
3  | |         $(
4  | |             #[derive(Clone, bincode::Encode, bincode::Decode)]
   | |                             ^^^^^^^^^^^^^^^
   | |                             |
   | |                             not found in this scope
   | |                             in this derive macro expansion (#2)
...  |
7  | |     }
8  | | }
   | |_- in this expansion of `dv!` (#1)
...
11 | / dv! {
12 | |     pub struct Foo {},
13 | |     pub enum Bar {
14 | |         A(Foo),
15 | |         B,
16 | |     }
17 | | }
   | |_- in this macro invocation (#1)
   |
  ::: /home/lxb/.cargo/registry/src/github.com-1ecc6299db9ec823/bincode_derive-2.0.0-rc.1/src/lib.rs:9:1
   |
9  |   pub fn derive_encode(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
   |   ------------------------------------------------------------------------------- in this expansion of `#[derive(bincode::Encode)]` (#2)
macro_rules! dv {
    ($($t:item),+) => {
        $(
            #[derive(Clone, bincode::Encode, bincode::Decode)]
            $t
        )+
    }
}

// Doesn't compile
dv! {
    pub struct Foo {},
    pub enum Bar {
        A(Foo),
        B,
    }
}

// Compiles
#[derive(Clone, bincode::Encode, bincode::Decode)]
pub struct Foo2 {}
#[derive(Clone, bincode::Encode, bincode::Decode)]
pub enum Bar2 {
    A(Foo2),
    B,
}
[package]
name = "bug"
version = "0.1.0"
edition = "2021"

[dependencies]
bincode = { version = "2.0.0-rc.1", default-features = false, features = ["derive"] }

This doesn't seem to happen with Decode

@trevyn
Copy link
Contributor

trevyn commented Oct 9, 2022

This looks like a macro hygiene thing, and I don't see an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants