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
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()}
Resolve `$crate`s for pretty-printing at more appropriate time
Doing it in `BuildReducedGraphVisitor` wasn't a good idea, identifiers wasn't actually visited half of the time.
As a result some `$crate`s weren't resolved and were therefore pretty-printed as `$crate` literally, which turns into two tokens during re-parsing of the pretty-printed text.
Now we are visiting and resolving `$crate` identifiers in an item right before sending that item to a proc macro attribute or derive.
Fixes#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 receiveIdent { 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 intoPunct { ch: '$' }
+Ident { ident: "crate" }
which rustc refuses to parse down the line.$crate
to disintegrate into$
+crate
and stop that from happening (preferred),$
+crate
where it appears in procedural macro output.repro_macros/src/lib.rs
repro/src/lib.rs
Mentioning @petrochenkov since you worked on #56647.
Mentioning @alexcrichton.
rustc 1.33.0-nightly (2d3e909 2018-12-22)
The text was updated successfully, but these errors were encountered: