File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use std:: fmt;
4
4
use std:: iter;
5
- use std:: panic;
5
+ use std:: panic:: { self , PanicInfo } ;
6
6
use std:: str:: FromStr ;
7
7
8
8
use proc_macro;
@@ -59,11 +59,21 @@ fn nightly_works() -> bool {
59
59
// not occur, they need to call e.g. `proc_macro2::Span::call_site()` from
60
60
// the main thread before launching any other threads.
61
61
INIT . call_once ( || {
62
+ type PanicHook = Fn ( & PanicInfo ) + Sync + Send + ' static ;
63
+
64
+ let null_hook: Box < PanicHook > = Box :: new ( |_panic_info| { /* ignore */ } ) ;
65
+ let sanity_check = & * null_hook as * const PanicHook ;
62
66
let original_hook = panic:: take_hook ( ) ;
63
- panic:: set_hook ( Box :: new ( |_panic_info| { /* ignore */ } ) ) ;
67
+ panic:: set_hook ( null_hook) ;
68
+
64
69
let works = panic:: catch_unwind ( || proc_macro:: Span :: call_site ( ) ) . is_ok ( ) ;
65
70
WORKS . store ( works as usize + 1 , Ordering :: SeqCst ) ;
71
+
72
+ let hopefully_null_hook = panic:: take_hook ( ) ;
66
73
panic:: set_hook ( original_hook) ;
74
+ if sanity_check != & * hopefully_null_hook {
75
+ panic ! ( "observed race condition in proc_macro2::nightly_works" ) ;
76
+ }
67
77
} ) ;
68
78
nightly_works ( )
69
79
}
You can’t perform that action at this time.
0 commit comments