File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ pub(crate) fn inside_proc_macro() -> bool {
1616 inside_proc_macro ( )
1717}
1818
19+ pub ( crate ) fn force_fallback ( ) {
20+ WORKS . store ( 1 , Ordering :: SeqCst ) ;
21+ }
22+
23+ pub ( crate ) fn unforce_fallback ( ) {
24+ initialize ( ) ;
25+ }
26+
1927// Swap in a null panic hook to avoid printing "thread panicked" to stderr,
2028// then use catch_unwind to determine whether the compiler's proc_macro is
2129// working. When proc-macro2 is used from outside of a procedural macro all
Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ use std::str::FromStr;
1414use std:: vec;
1515use unicode_xid:: UnicodeXID ;
1616
17+ /// Force use of proc-macro2's fallback implementation of the API for now, even
18+ /// if the compiler's implementation is available.
19+ pub fn force ( ) {
20+ crate :: detection:: force_fallback ( ) ;
21+ }
22+
23+ /// Resume using the compiler's implementation of the proc macro API if it is
24+ /// available.
25+ pub fn unforce ( ) {
26+ crate :: detection:: unforce_fallback ( ) ;
27+ }
28+
1729#[ derive( Clone ) ]
1830pub ( crate ) struct TokenStream {
1931 inner : Vec < TokenTree > ,
Original file line number Diff line number Diff line change @@ -99,7 +99,11 @@ use std::str::FromStr;
9999mod detection;
100100#[ macro_use]
101101mod strnom;
102- mod fallback;
102+
103+ // Public for proc_macro2::fallback::force() and unforce(), but those are quite
104+ // a niche use case so we omit it from rustdoc.
105+ #[ doc( hidden) ]
106+ pub mod fallback;
103107
104108#[ cfg( not( wrap_proc_macro) ) ]
105109use crate :: fallback as imp;
You can’t perform that action at this time.
0 commit comments