mashup icon indicating copy to clipboard operation
mashup copied to clipboard

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

Open dtolnay opened this issue 7 years ago • 3 comments

#[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 avatar Jul 09 '18 17:07 dtolnay

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

dtolnay avatar Jul 09 '18 17:07 dtolnay

@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?

csmoe avatar May 25 '19 15:05 csmoe

You shouldn't need separate substitution macros for that.

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

dtolnay avatar May 25 '19 16:05 dtolnay