Fix review comment

This commit is contained in:
bjorn3 2021-10-12 13:36:01 +02:00
parent f0b0040bf8
commit 07ee9bba15

View File

@ -12,24 +12,16 @@ pub(crate) fn inside_proc_macro() -> bool {
_ => {}
}
#[cfg(feature = "is_available")]
{
proc_macro::is_available()
}
#[cfg(not(feature = "is_available"))]
{
INIT.call_once(initialize);
inside_proc_macro()
}
}
pub(crate) fn force_fallback() {
WORKS.store(1, Ordering::SeqCst);
}
pub(crate) fn unforce_fallback() {
WORKS.store(0, Ordering::SeqCst);
initialize();
}
// Swap in a null panic hook to avoid printing "thread panicked" to stderr,
@ -57,6 +49,13 @@ pub(crate) fn unforce_fallback() {
// not occur, they need to call e.g. `proc_macro2::Span::call_site()` from
// the main thread before launching any other threads.
fn initialize() {
#[cfg(feature = "is_available")]
{
WORKS.store(proc_macro::is_available() as usize + 1, Ordering::SeqCst);
}
#[cfg(not(feature = "is_available"))]
{
type PanicHook = dyn Fn(&PanicInfo) + Sync + Send + 'static;
let null_hook: Box<PanicHook> = Box::new(|_panic_info| { /* ignore */ });
@ -73,3 +72,4 @@ fn initialize() {
panic!("observed race condition in proc_macro2::inside_proc_macro");
}
}
}