-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
proc_macro::is_available() #71400
proc_macro::is_available() #71400
Conversation
Reassigning per #71268 (comment) because @eddyb is occupied. |
LGTM, but it needs a tracking issue. FCP and official team approval can be done during stabilization. |
@bors r=petrochenkov |
📌 Commit 3bd742f has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#71256 (Lint must_use on mem::replace) - rust-lang#71350 (Error code explanation extra check) - rust-lang#71369 (allow wasm32 compilation of librustc_data_structures/profiling.rs) - rust-lang#71400 (proc_macro::is_available()) - rust-lang#71440 (Implement `Copy` for `AllocErr`) Failed merges: r? @ghost
Seems fine, the panic=abort situation leaves us no other options. cc @mystor, who, IIRC, wanted a "default server" which would eliminate the need for |
Something like a fallback server could make |
This PR adds
proc_macro::is_available() -> bool
to determine whether proc_macro has been made accessible to the currently running program.The proc_macro crate is only intended for use inside the implementation of procedural macros. All the functions in the crate panic if invoked from outside of a procedural macro, such as from a build script or unit test or ordinary Rust binary.
Unfortunately those panics made it impossible for libraries that are designed to support both macro and non-macro use cases (e.g. Syn) to be used from binaries that are compiled with panic=abort. In panic=unwind mode we're able to attempt a proc macro call inside catch_unwind and use libproc_macro's result if it succeeds, otherwise fall back to a non-macro alternative implementation. But in panic=abort there was no way to determine which implementation needs to be used.
r? @eddyb
attn: @petrochenkov @adetaylor
ref: dtolnay/cxx#130