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

proc_macro::is_available() #71400

Merged
merged 2 commits into from
Apr 23, 2020
Merged

proc_macro::is_available() #71400

merged 2 commits into from
Apr 23, 2020

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Apr 21, 2020

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2020
@dtolnay dtolnay added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 21, 2020
@dtolnay
Copy link
Member Author

dtolnay commented Apr 22, 2020

Reassigning per #71268 (comment) because @​eddyb is occupied.

r? @petrochenkov

@rust-highfive rust-highfive assigned petrochenkov and unassigned eddyb Apr 22, 2020
@petrochenkov
Copy link
Contributor

LGTM, but it needs a tracking issue.

FCP and official team approval can be done during stabilization.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2020
@dtolnay
Copy link
Member Author

dtolnay commented Apr 22, 2020

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Apr 22, 2020

📌 Commit 3bd742f has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 22, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2020
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
@bors bors merged commit 0f80653 into rust-lang:master Apr 23, 2020
@dtolnay dtolnay deleted the isavailable branch April 23, 2020 03:47
@eddyb
Copy link
Member

eddyb commented Apr 27, 2020

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 proc-macro2.

@mystor
Copy link
Contributor

mystor commented Apr 30, 2020

Something like a fallback server could make is_available not make as much sense, as it could theoretically always be true. That being said, I think fixing the panic-catching jank within proc-macro2 is worth that potential future confusion, especially considering that (to my knowledge) there's no existing plan or design for a fallback proc_macro server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants