serde_derive panicks when a doc comment is added to an item via a macro

Created on 1 Oct 2016  路  1Comment  路  Source: serde-rs/serde

Compiling the following code:

#![feature(rustc_macro)]

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


macro_rules! event {
    (   #[$attr:meta]
        pub struct $name:ident($content_type:ty);
    ) => {
        #[$attr]
        #[derive(Debug, Deserialize, Serialize)]
        pub struct $name {
            /// The event's content.
            content: $content_type,
        }
    }
}

event! {
    /// A custom basic event not covered by the Matrix specification.
    pub struct CustomEvent(String);
}

Results in:

   Compiling serde_derive_error v0.1.0 (file:///Users/jimmy/Code/serde_derive_error)
error: custom derive attribute panicked
  --> src/lib.rs:12:25
   |
12 |         #[derive(Debug, Deserialize, Serialize)]
   |                         ^^^^^^^^^^^
...
20 | event! {
   | - in this macro invocation
   |
   = help: message: called `Result::unwrap()` on an `Err` value: "failed to parse macro input: \"#[derive(Deserialize)]\\n#[doc = r\\\" A custom basic event not covered by the Matrix specification.\\\"]\\n#[derive(Debug, Serialize)]\\npub struct CustomEvent {\\n    /// The event\\\'s content.\\n    content: String,\\n}\\n\""

error: Could not compile `serde_derive_error`.

I'm using:

  • rustc 1.14.0-nightly (86affcdf6 2016-09-28)
  • serde 0.8.10
  • serde_derive 0.8.10
bug

Most helpful comment

Raw string literals r"..." were not implemented in syn. I released syn 0.8.4 with a fix, confirmed that your snippet expands successfully, and added CustomEvent as a test case.

>All comments

Raw string literals r"..." were not implemented in syn. I released syn 0.8.4 with a fix, confirmed that your snippet expands successfully, and added CustomEvent as a test case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dtolnay picture dtolnay  路  3Comments

swfsql picture swfsql  路  3Comments

vityafx picture vityafx  路  3Comments

pitkley picture pitkley  路  3Comments

dtolnay picture dtolnay  路  3Comments