Is there a documentation for the panic "Procedural macro API is used outside of a procedural macro"?
I'm building a procedural macro crate, which links and executes a native library, and the compiler crashes with that error (stacktrace: https://users.rust-lang.org/t/procedural-macro-api-is-used-outside-of-a-procedural-macro/30841).
I don't understand why the panic originates in the library: the library does not use the
proc_macro API, but only the
@Federico the proc_macro2 crate internally uses the proc_macro API
@simulacrum I see, thanks! I expected
proc_macro2to be a opaque wrapper around
proc_macro, without the limitations of the latter.
The limitations are sort of inherent and can't be removed by a library I believe
(beyond duplicating the entire compiler, but even then you don't get what you want since the result won't work with rustc)
But what does "outside of a procedural macro" exactly mean? Outside the crate that implements a procedural macro?
the context is loosely I believe same-thread
just based on the snippets in that post I would expect it to work but more info might be needed on how exactly PLUGIN is defined/what it does
Can it be that also calling a native library crosses the boundary? The plugin is a Rust crate, linked as native library in order to allow the procedural macro crate to choose via an environment variable which implementation to use
The code is here: https://github.com/viperproject/rust-contracts
Plausible, yeah, I'm not entirely sure myself when TLS changes
and/or is no longer accessible
I would check if you can reproduce when not dynamically loading the library (just regular cargo dep)
that way you can better isolate the failure
you could also plausibly test if it's working by declaring via
thread_local! a thread local and seeing if you can access the same local from a separate library and/or googling that
Thanks for the info!