Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Mashup macro cannot be invoked more than once in the same scope #5

Open
dtolnay opened this issue Jul 9, 2018 · 3 comments
Open

Mashup macro cannot be invoked more than once in the same scope #5

dtolnay opened this issue Jul 9, 2018 · 3 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jul 9, 2018

#[macro_use]
extern crate mashup;

mashup! {
    sub1["y"] = Y y;
}

mashup! {
    sub2["z"] = Z z;
}

sub1! {
    struct "y";
}

sub2! {
    struct "z";
}

fn main() {}
error[E0428]: the name `ProcMacroHack` is defined multiple times
  --> src/main.rs:4:1
   |
4  | / mashup! {
5  | |     sub1["y"] = Y y;
6  | | }
   | |_^ `ProcMacroHack` redefined here
7  | 
8  | / mashup! {
9  | |     sub2["z"] = Z z;
10 | | }
   | |_- previous definition of the type `ProcMacroHack` here
   |
   = note: `ProcMacroHack` must be defined only once in the type namespace of this module
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
@dtolnay
Copy link
Owner Author

dtolnay commented Jul 9, 2018

This limitation can be lifted once function-like procedural macros in item context are stabilized.

@csmoe
Copy link

csmoe commented May 25, 2019

@dtolnay If I still wanna do this for fields like:

mashup! {
    get["get" $field] = get_ $field;
}
mashup! {
    set["set" $field] = set_ $field;
}

Is there any hack for that?

@dtolnay
Copy link
Owner Author

dtolnay commented May 25, 2019

You shouldn't need separate substitution macros for that.

mashup! {
    m["get" $field] = get_ $field;
    m["set" $field] = set_ $field;
}

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

No branches or pull requests

2 participants