Add a feature for linking to `proc-macro`
This commit adds a feature to this crate which enables linking to the
upstream `proc_macro` crate. This should help this compile on targets
which don't have `proc_macro` and allow it to also be suitable for
embedding in Rust binaries.
This feature is turned on by default for backwards compatibility right
now.
diff --git a/src/lib.rs b/src/lib.rs
index d08988c..31ba765 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,7 @@
#![cfg_attr(feature = "nightly", feature(proc_macro))]
+#[cfg(feature = "proc-macro")]
extern crate proc_macro;
#[cfg(not(feature = "nightly"))]
@@ -67,12 +68,14 @@
}
}
+#[cfg(feature = "proc-macro")]
impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> TokenStream {
TokenStream(inner.into())
}
}
+#[cfg(feature = "proc-macro")]
impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> proc_macro::TokenStream {
inner.0.into()
@@ -175,7 +178,7 @@
}
/// This method is only available when the `"nightly"` feature is enabled.
- #[cfg(feature = "nightly")]
+ #[cfg(all(feature = "nightly", feature = "proc-macro"))]
pub fn unstable(self) -> proc_macro::Span {
self.0.unstable()
}