Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use code with proc-macro-error-2 in tests? #8

Open
Miha-Rozina opened this issue Feb 20, 2025 · 1 comment
Open

How to use code with proc-macro-error-2 in tests? #8

Miha-Rozina opened this issue Feb 20, 2025 · 1 comment

Comments

@Miha-Rozina
Copy link

I have unit tests written for all of my proc macros by using proc_macro2 in my implementation and running the code as a normal Rust test. However if I use proc-macro-error-2 I get errors like

proc-macro-error2 API cannot be used outside of `entry_point` invocation,

If I wrap my macro code in a proc_macro_error2::entry_point call I get this error

procedural macro API is used outside of a procedural macro

I think the problem stems from the fact that entry_point() returns a proc_macro::TokenStream instead of proc_macro2::TokenStream. Is there another supported way of how to invoke code that contains proc-macro-error-2 code in a test environment?

@Miha-Rozina
Copy link
Author

Miha-Rozina commented Feb 20, 2025

I've actually just went ahead and made a pull request that adds support for unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant