Skip to content

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

New issue

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

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

Already on GitHub? # to your account

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.

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

No branches or pull requests

1 participant