magiclen / educe

This crate offers procedural macros designed to facilitate the swift implementation of Rust's built-in traits.
MIT License
131 stars 11 forks source link

Panic when other attributes contain non-literal tokens #9

Closed jf2048 closed 1 year ago

jf2048 commented 1 year ago

Hello, thank you for this crate. I was trying it out and I found this sample program fails with a compile error:

Cargo.toml:

[package]
name = "educetest"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.2.3", features = ["derive"] }
educe = { version = "0.4.21", default-features = false, features = ["Default"] }

src/main.rs:

#[derive(clap::Parser, educe::Educe)]
#[educe(Default)]
#[command(author, version, about, long_about = None)]
struct Cli {
    /// Network port to use
    #[educe(Default = 1000)]
    #[arg(value_parser = clap::value_parser!(u16).range(1..))]
    port: u16,
}

fn main() {}

Output:

error: proc-macro derive panicked
 --> src/main.rs:1:24
  |
1 | #[derive(clap::Parser, educe::Educe)]
  |                        ^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: Error("expected literal")

However it goes away when I remove the #[arg(...)] attribute. It seems Educe is trying to parse all other attributes. Should it skip them and only parse #[educe(...)] attributes?