mcarton / rust-derivative

A set of alternative `derive` attributes for Rust
Apache License 2.0
415 stars 46 forks source link

The `#derive(Derivative)` attribute does not work in macro afer updating to the latest nightly. #75

Closed A1-Triard closed 4 years ago

A1-Triard commented 4 years ago

After updating to the latest nightly, #derive(Derivative) does not work in macro anymore.

#[macro_use]
extern crate derivative;

macro_rules! empty_struct {
    (
        $(#[$attr:meta])* $name:ident
    ) => {
        $(#[$attr])* 
        struct $name;
    };
}

empty_struct!(
    #[derive(Derivative)]
    #[derivative(Debug)]
    MyStruct
);

Compiler error:

  --> src/main.rs:14:14
   |
8  |           $(#[$attr])* 
   |  ___________-
9  | |         struct $name;
   | |_____________________- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
...
14 |       #[derive(Derivative)]
   |                ^^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Version info:

$ rustup --version
rustup 1.22.1 (b01adbbc3 2020-07-08)
$ cargo --version
cargo 1.47.0-nightly (51b66125b 2020-08-19)
$ rustc --version
rustc 1.48.0-nightly (d006f5734 2020-08-28)

Version of derivative: 2.1.1

A1-Triard commented 4 years ago

Nevermind. educe works.