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 }}
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
macro_rules! good {() => {{let x = 0;
let y = 1;
foo::sum!(x, y)}}}macro_rules! weird {($expr:expr) => {{let z = 3;
foo::sum!(z, $expr)}}}fnmain(){let a = good!();let b = weird!(2);//~ error: cannot find value `z` in this scopelet z = 99;let c = weird!(1);// evaluates to 100}
Here I expected b to compile and c to evaluate to 4.
Expansion
cargo expand-ion of let b:
let b = {let z = 3;{enumProcMacroHack{Value = ("z, 2",0).1,}
z + 2}};
Copy-pasting this into the original file produces the expected output (as in it compiles).
Is this a known limitation of embedding a proc-macro-hack in a macro_rules macro or is this a compiler bug? Adding support_nested and / or fake_call_site to the proc_macro_hack re-export didn't help.
The text was updated successfully, but these errors were encountered:
This is a compiler bug; rust-lang/rust#43081. The compiler currently has no ability to convert from its syntax tree of enum ProcMacroHack { Value = (stringify! { z , $expr }, 0).1, } into a TokenStream for passing into foo::sum. The syntax::ast::Expr inside $expr causes it to just lose all spans in the entire macro input when doing the conversion.
Depending on the use case you can usually work around this by doing less parsing in macro_rules and more parsing in your proc macro to avoid passing around syntax::ast::Expr tokens.
macro_rules! weird {($($expr:tt)*) => {{let z = 3;
repro::sum!(z, $($expr)*)}}}
Thanks for the prompt answer! The work around works perfectly for my use case. I'll add a note to the documentation of my proc-macro-hack macro so others won't run into this rustc bug.
You probably don't want to keep a non-actionable, upstream bug so I'll close this. Thanks again.
Tested with:
- nightly-2020-05-30
- nightly-2020-04-30
- 1.40.0
- 1.37.0
This commit fixes non-trivial patterns causing an error saying
"unexpected token". This is done by parenthesizing `$p`. This might have
something to do with an input pattern being wrapped by a
`None`-delimited group and I suspect this might have been overlooked by
the crater run <rust-lang/rust#72622>, but I'm
not sure.
This commit also implements a work-around for the issue
<dtolnay/proc-macro-hack#46> by capturing
the input expression by `$($in:tt)*`. The first work-around might have
revealed this issue.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
STR
Implementation
Export
Use
Here I expected
b
to compile andc
to evaluate to4
.Expansion
cargo expand
-ion oflet b
:Copy-pasting this into the original file produces the expected output (as in it compiles).
Metadata
Is this a known limitation of embedding a proc-macro-hack in a macro_rules macro or is this a compiler bug? Adding
support_nested
and / orfake_call_site
to theproc_macro_hack
re-export didn't help.The text was updated successfully, but these errors were encountered: