Closed danieleades closed 2 years ago
Moved to quote repo because this is fundamentally about quote! { #[doc = #doc] }
vs quote! { /// ... }
which has nothing to do with syn.
You can control the exact formatting of the string literal token this way:
use proc_macro2::Literal;
let doc = format!("r{:?}", doc).parse::<Literal>().unwrap();
quote! { #[doc = #doc] }
Hi there, hoping for some assistance!
I'm writing unit tests for a derive macro, and having a bit of trouble.
My derive macro generates setters for fields in a struct, and preserves the doc comments on the fields as doc comments on the setters.
i'm parsing the original doc comment into a string, and then generating an attribute from that string like so-
that seems to work. the problem comes when i try to compare it to output generated from the following-
the doc attribute parsed from the second example is of the form
#[doc = r"<comment>"
, whereas the doc comment produced from the first example is of the form#[doc = "<comment>"
(a regular string literal, as opposed to a raw string literal). This makes comparisons in unit test a little tricky. Where am I going wrong? How can i construct a doc comment attribute with a raw string literal?