JelteF / derive_more

Some more derive(Trait) options
MIT License
1.73k stars 123 forks source link

Cannot find `_derive_more_display_formatter` when `Display` is derived via a declarative macro #367

Closed mamekoro closed 4 months ago

mamekoro commented 5 months ago

rustc: 1.78.0 derive_more: 0.99.17

I tried to make a set of derives reusable by defining a declarative macro, but I get the error cannot find value `_derive_more_display_formatter` in this scope.

Here is a reproduction.

cargo new repro
cd repro
cargo add derive_more

cat <<'EOF' >src/main.rs
macro_rules! derive_recordable {
    ($item:item) => {
        #[derive(
            Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash,
            ::derive_more::Display,
        )]
        $item
    };
}

derive_recordable! {
    pub enum Event {
        #[display(fmt = "start")]
        Start,
        #[display(fmt = "move({dx}, {dy})")]
        Move { dx: i8, dy: i8 },
        #[display(fmt = "end")]
        End,
    }
}

fn main() {}
EOF

cargo build

I got these errors;

error[E0425]: cannot find value `_derive_more_display_formatter` in this scope
  --> src/main.rs:13:11
   |
13 |         #[display(fmt = "start")]
   |           ^^^^^^^ not found in this scope

error[E0425]: cannot find value `_derive_more_display_formatter` in this scope
  --> src/main.rs:15:11
   |
15 |         #[display(fmt = "move({dx}, {dy})")]
   |           ^^^^^^^ not found in this scope

error[E0425]: cannot find value `_derive_more_display_formatter` in this scope
  --> src/main.rs:17:11
   |
17 |         #[display(fmt = "end")]
   |           ^^^^^^^ not found in this scope
JelteF commented 4 months ago

Is this issue also present if you use derive more version 1.0.0-beta.6 ?

mamekoro commented 4 months ago

Thanks, this error seems to be gone in v1.0.0-beta.6.

cargo new repro
cd repro
cargo add derive_more@1.0.0-beta.6 --features display

cat <<'EOF' >src/main.rs
macro_rules! derive_recordable {
    ($item:item) => {
        #[derive(
            Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash,
            ::derive_more::Display,
        )]
        $item
    };
}

derive_recordable! {
    pub enum Event {
        #[display("start")]
        Start,
        #[display("move({dx}, {dy})")]
        Move { dx: i8, dy: i8 },
        #[display("end")]
        End,
    }
}

fn main() {}
EOF

# now compiles successfully
cargo build

I'm going to close this issue for now, but is there any chance that this bug will be fixed before version 1.0.0?