You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$crate unexpectedly disintegrates depending on unrelated macro invocations #57089
I have proc macros mac! which is function-like and #[attr] which is an attribute. Both of them simply emit their input unchanged (input.into_iter().collect()).
I have an invocation of both macros from another crate which passes tokens containing $crate. In the code below, everything is working as expected and both macros receive Ident { ident: "$crate" } in their input.
Now for the broken bit: I observed some spooky action at a distance in which changing the behavior of mac! affects the input of the totally unrelated invocation of #[attr]. The input of #[attr] decomposes into Punct { ch: '$' } + Ident { ident: "crate" } which rustc refuses to parse down the line.
Either we need to find out what is causing $crate to disintegrate into $ + crate and stop that from happening (preferred),
Or the parser needs to accept an appropriately spanned $ + crate where it appears in procedural macro output.
repro_macros/src/lib.rs
externcrate proc_macro;use proc_macro::TokenStream;#[proc_macro]pubfnmac(input:TokenStream) -> TokenStream{println!("MAC INPUT: {:#?}", input);// Change this to `false` to observe the spooky effect on the input of #[attr].iftrue{
input.into_iter().collect()}else{TokenStream::new()}}#[proc_macro_attribute]pubfnattr(_args:TokenStream,input:TokenStream) -> TokenStream{println!("ATTR INPUT: {:#?}", input);
input.into_iter().collect()}
Activity
petrochenkov commentedon Dec 27, 2018
Fixed in #57155
Auto merge of #57155 - petrochenkov:dcrate3, r=dtolnay