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

Use proc_macro::is_available() instead of panic for proc macro detection #218

Closed
dtolnay opened this issue Apr 25, 2020 · 1 comment
Closed
Assignees

Comments

@dtolnay
Copy link
Owner

dtolnay commented Apr 25, 2020

We currently rely on a catch_unwind to detect whether Span::call_site() works, i.e. whether we are executing inside of a procedural macro as opposed to any other binary.

https://github.com/alexcrichton/proc-macro2/blob/eed1e2fe228a7b26241847c2b1a79031abab59e8/src/wrapper.rs#L77

Unfortunately this is incompatible with using proc-macro2 (or quote, syn) in a non-macro way inside of binaries that are built with panic=abort, as they will just abort on that line.

rust-lang/rust#71436 adds a proc_macro::is_available() function to do this detection in a way that no longer relies on panicking.

Once the first 1.45-beta release is available, we should add some detection in build.rs to begin using proc_macro::is_available() on dev compiler builds.

@dtolnay
Copy link
Owner Author

dtolnay commented May 1, 2020

For now, #220 allows a workaround for some of the need for this. Non-macros that want to support panic=abort can call proc_macro2::fallback::force() to bypass the panicking codepath in proc macro detection.

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