Skip to content

Commit 20fdacd

Browse files
authored
Merge pull request #220 from alexcrichton/force
Add a way to force fallback implementation
2 parents 3bb54e8 + b128cd6 commit 20fdacd

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/detection.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/fallback.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ use std::str::FromStr;
1414
use std::vec;
1515
use 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)]
1830
pub(crate) struct TokenStream {
1931
inner: Vec<TokenTree>,

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ use std::str::FromStr;
9999
mod detection;
100100
#[macro_use]
101101
mod 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))]
105109
use crate::fallback as imp;

0 commit comments

Comments
 (0)