nrc / derive-new

derive simple constructor functions for Rust structs
MIT License
525 stars 35 forks source link

Error 'Invalid #[new] attribute' #33

Closed Undin closed 6 years ago

Undin commented 6 years ago

Using derive-new 0.5.1 got the following error

error: proc-macro derive panicked
   |
40 | #[derive(new, Serialize, Debug)]
   |          ^^^
   |
   = help: message: Invalid #[new] attribute: #[new(skip_serializing_if = ..)]

Struct definition:

#[derive(new, Serialize, Debug)]
pub struct SendMessageData<'a> {
    pub chat_id: i64,
    pub text: &'a str,
    pub parse_mode: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reply_markup: Option<InlineKeyboardMarkup<'a>>
}
nrc commented 6 years ago

This is fixed in 0.5.2 (sorry, this was fixed a little while ago, but I forgot to publish a new version).

tilacog commented 6 years ago

I'm still having the same error message using derive-new 0.5.2 with the code @Undin supplied.

The error can also be reproduced with this smaller snippet:

#[macro_use] extern crate derive_new;
#[macro_use] extern crate serde_derive;

#[derive(new, Serialize)]
struct Struct {
    field_a: u8,
    #[serde(skip)]
    field_b: u8,
}

Error:

error: proc-macro derive panicked
 --> src/main.rs:4:10
  |
4 | #[derive(new, Serialize)]
  |          ^^^
  |
  = help: message: Invalid #[new] attribute: #[new(skip)]

the code compiles just fine when the #[serde(skip)] field attribute is removed.

Cargo.toml used:

[dependencies]
derive-new = "0.5.2"
serde = "1.0.33"
serde_derive = "1.0.33"