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

declarative macro compilation fails with serde derive #42708

Closed
milyin opened this issue Jun 16, 2017 · 2 comments
Closed

declarative macro compilation fails with serde derive #42708

milyin opened this issue Jun 16, 2017 · 2 comments
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@milyin
Copy link

milyin commented Jun 16, 2017

Declarative macro with '#[derive(Serialize)]' inside generates compilation error. The same old-style macro works ok.

I tried this code:

`#![feature(decl_macro)]
extern crate serde;
#[macro_use] extern crate serde_derive;

macro_rules! old_macro { 
    ($name:ident) => {
        #[derive(Serialize)]
        struct $name {
            name: &'static str
        }
    }
}

macro new_macro($name:ident) {
    #[derive(Serialize)]
    struct $name {
        name: &'static str
    }
}

old_macro!(Name1);
new_macro!(Name2);

fn main() {
}

'old_macro' and 'new_marcro' are equal so I expect that both should be compiled. Instead compiler failed on 'new_macro' (but compiled 'old_macro' successfully):

error[E0609]: no field `name` on type `&Name2`
  --> src\main.rs:15:14
   |
15 |     #[derive(Serialize)]
   |              ^^^^^^^^^
...
22 | new_macro!(Name2);
   | ------------------ in this macro invocation

Meta

C:\Temp\bug>rustc --version
rustc 1.19.0-nightly (554c685b0 2017-06-14)

C:\Temp\bug>cargo rustc --verbose
       Fresh serde v1.0.8
       Fresh unicode-xid v0.0.4
       Fresh quote v0.3.15
       Fresh synom v0.11.3
       Fresh syn v0.11.11
       Fresh serde_derive_internals v0.15.1
       Fresh serde_derive v1.0.8
   Compiling bug v0.1.0 (file:///C:/Temp/bug)
     Running `rustc --crate-name bug src\main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1ffe308d662129d2 -C extra-filename=-1ffe308d66
2129d2 --out-dir C:\Temp\bug\target\debug\deps -L dependency=C:\Temp\bug\target\debug\deps --extern serde_derive=C:\Temp\bug\target\debug\deps\serde_derive-7311
4808ba8f6d5d.dll --extern serde=C:\Temp\bug\target\debug\deps\libserde-78efb8229e554e58.rlib`
error[E0609]: no field `name` on type `&Name2`
  --> src\main.rs:15:14
   |
15 |     #[derive(Serialize)]
   |              ^^^^^^^^^
...
22 | new_macro!(Name2);
   | ------------------ in this macro invocation

error: aborting due to previous error(s)

error: Could not compile `bug`.

Caused by:
  process didn't exit successfully: `rustc --crate-name bug src\main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1ffe308d662129d2 -C ext
ra-filename=-1ffe308d662129d2 --out-dir C:\Temp\bug\target\debug\deps -L dependency=C:\Temp\bug\target\debug\deps --extern serde_derive=C:\Temp\bug\target\debug
\deps\serde_derive-73114808ba8f6d5d.dll --extern serde=C:\Temp\bug\target\debug\deps\libserde-78efb8229e554e58.rlib` (exit code: 101)
@Mark-Simulacrum Mark-Simulacrum added A-syntaxext Area: Syntax extensions A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed A-syntaxext Area: Syntax extensions labels Jun 17, 2017
@arielb1
Copy link
Contributor

arielb1 commented Jun 17, 2017

cc @jseyfried - looks like hygiene running amok.

@jseyfried jseyfried self-assigned this Jun 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@jseyfried
Copy link
Contributor

Sorry for the delay getting to this; fixed in #46343.

arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
bors added a commit that referenced this issue Dec 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants