Closed
Description
Describe the Bug
Since the update to rust 1.47.0, typescript_custom_section doesn't work with literal captures expanded by macro.
In previous versions of rust, everything worked as expected.
The reported error is
Expected a string literal to be used with #[wasm_bindgen(typescript_custom_section)]
Reproduction
macro_rules! generate_ts {
($lit:literal) => {
#[wasm_bindgen(typescript_custom_section)]
const _: &str = $lit;
};
}
generate_ts!("TEST");
The snippet above represent the code that used to work, but doesn't anymore. I've printed the actual AST that syn::ItemConst::macro_parse
received, and got this:
Group(
ExprGroup {
attrs: [],
group_token: Group,
expr: Lit(
ExprLit {
attrs: [],
lit: Str(LitStr { token: "TEST" })
}
)
}
)
Which means, now rust expands the literal
(and possibly other) captures as an expression group with one item, and this should probably be handled in various places in the parser.
Current workaround
I managed to fix it in my specific case by using tt
capture instead of literal
, but this is obviously more general than i would like.