Skip to content

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

@dtolnay

Description

@dtolnay

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions