mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-27 01:20:48 +00:00
Fix review comment
This commit is contained in:
parent
f0b0040bf8
commit
07ee9bba15
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user