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 know it's not a Syn issue, but I have problems with using function parameters in macro-generated code.
I'm writing a procedural macro, which injects some code on the beginning of a function. The code uses function's parameters. Up to now it used Syn 0.11 and after upgrading to 0.12 it still worked fine.
After upgrade I enabled proc-macro2's nightly feature to enable error reporting in code processed by macro. Suddenly all the tests, where injected code used function's parameters started to fail:
error[E0425]: cannot find value `x` in this scope
--> tests/injecting.rs:641:5
|
641 | #[mockable]
| ^^^^^^^^^^^ not found in this scope
I tried boiling issue down to minimum example and came up with a primitive macro:
BEFORE:
pub fn args_test(x: u32) { assert!(x > 1) }
AFTER:
pub fn args_test ( x : u32 ) { println ! ( "{}" , x ) }
error[E0425]: cannot find value `x` in this scope
--> tests/injecting.rs:662:1
|
662 | #[print_x]
| ^^^^^^^^^^ not found in this scope
Manually replacing annotated function with pub fn args_test ( x : u32 ) { println ! ( "{}" , x ) } gives no errors, the code is fine.
The fun escalated when I removed the nightly proc-macro2 feature: real macro started working again, but the boiled-down print_x still failed with the same error.
It's really confusing, I see no logic behind these errors. I know, if it's not a Syn problem, but could anybody help me with it? Thank you!
The text was updated successfully, but these errors were encountered:
This has to do with whether the x token is spanned to resolve at the macro call site or at the macro def site. Check out rust-lang/rust#45934 for some background, and see this example of a macro that uses def site and call site spans correctly.
I know it's not a Syn issue, but I have problems with using function parameters in macro-generated code.
I'm writing a procedural macro, which injects some code on the beginning of a function. The code uses function's parameters. Up to now it used Syn 0.11 and after upgrading to 0.12 it still worked fine.
After upgrade I enabled proc-macro2's
nightly
feature to enable error reporting in code processed by macro. Suddenly all the tests, where injected code used function's parameters started to fail:I tried boiling issue down to minimum example and came up with a primitive macro:
And used it:
It failed perfectly:
Manually replacing annotated function with
pub fn args_test ( x : u32 ) { println ! ( "{}" , x ) }
gives no errors, the code is fine.The fun escalated when I removed the
nightly
proc-macro2 feature: real macro started working again, but the boiled-downprint_x
still failed with the same error.It's really confusing, I see no logic behind these errors. I know, if it's not a Syn problem, but could anybody help me with it? Thank you!
The text was updated successfully, but these errors were encountered: