idanarye/rust-typed-builder

TypedBuilder derive panics on compile-time with `crate`

Closed this issue · 3 comments

The following is the error I get by the compiler:

error: proc-macro derive panicked
 --> src/packet/types/chat.rs:5:52
  |
5 | #[derive(Serialize, Deserialize, Debug, PartialEq, TypedBuilder)]
  |                                                    ^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: "failed to parse derive input: \"pub struct Chat {\\n    #[serde(flatten)]\\n    pub content: ChatContent,\\n    #[serde(skip_serializing_if = \\\"Vec::is_empty\\\")]\\n    pub extra: Vec<Chat>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub colour: Option<crate::chat::Colour>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub bold: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub italic: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub obfuscated: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub strikethrough: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub underlined: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub reset: Option<bool>,\\n    #[serde(skip_serializing_if = \\\"Option::is_none\\\")]\\n    pub insertion: Option<String>,\\n}\""

This is the struct and its uses:

// yes, these are 2018-edition uses
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Serialize, Deserialize, Debug, PartialEq, TypedBuilder)]
pub struct Chat {
    #[serde(flatten)]
    pub content: ChatContent,

    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub extra: Vec<Chat>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub colour: Option<crate::chat::Colour>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub bold: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub italic: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub obfuscated: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub strikethrough: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub underlined: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub reset: Option<bool>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub insertion: Option<String>,
}

A minimal working example to duplicate this is:

#[derive(TypedBuilder)]
pub struct Horse {
    owner: crate::HorseOwner, // this type doesn't need to exist, it panics either way
}

The crate keyword is incompatible with the version of syn you're using, which also happens to be ancient. 0.11.11 is from the 27th of April, 2017. The current version is 0.15.24 from the 9th of January 2019.

An update to syn would fix this, I reckon, and updating quote might be good to get along with it, as that is also ancient.

I've started an effort to update syn (the upgrade-syn-version branch), but it's not as simple as bumping the version number, as they did some major changes to the API - some of them I'm still trying to figure how to apply.

Still - I really need to get back to that task...

@idanarye I'd love to help out if I get around to disregard my grudge for the challenge that are proc-macros. I'll try to look into it this afternoon ^^

Done