Add a feature for linking to proc_macro.
This feature is enabled by default for backwards compatibility, but
it can be disabled in order to break the runtime dependency on the
dynamic library libproc_macro in the rustc toolchain.
diff --git a/src/buffer.rs b/src/buffer.rs
index 10ac5f6..d92a7a6 100644
--- a/src/buffer.rs
+++ b/src/buffer.rs
@@ -127,6 +127,7 @@
// and caution should be used when editing it. The public-facing interface is
// 100% safe but the implementation is fragile internally.
+#[cfg(feature = "proc-macro")]
use proc_macro as pm;
use proc_macro2::{Delimiter, Literal, Span, Term, TokenStream};
use proc_macro2::{Group, TokenTree, Op};
@@ -219,6 +220,7 @@
/// Creates a `TokenBuffer` containing all the tokens from the input
/// `TokenStream`.
+ #[cfg(feature = "proc-macro")]
pub fn new(stream: pm::TokenStream) -> TokenBuffer {
Self::new2(stream.into())
}
diff --git a/src/lib.rs b/src/lib.rs
index d881cd9..fc6d978 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -262,6 +262,7 @@
redundant_closure, needless_pass_by_value, redundant_field_names))]
extern crate proc_macro2;
+#[cfg(feature = "proc-macro")]
extern crate proc_macro;
extern crate unicode_xid;
@@ -572,7 +573,7 @@
/// #
/// # fn main() {}
/// ```
-#[cfg(feature = "parsing")]
+#[cfg(all(feature = "parsing", feature = "proc-macro"))]
pub fn parse<T>(tokens: proc_macro::TokenStream) -> Result<T, ParseError>
where
T: Synom,
diff --git a/src/synom.rs b/src/synom.rs
index 6a33f4f..935b7a8 100644
--- a/src/synom.rs
+++ b/src/synom.rs
@@ -149,6 +149,7 @@
//!
//! *This module is available if Syn is built with the `"parsing"` feature.*
+#[cfg(feature = "proc-macro")]
use proc_macro;
use proc_macro2;
@@ -225,6 +226,7 @@
fn parse2(self, tokens: proc_macro2::TokenStream) -> Result<Self::Output, ParseError>;
/// Parse tokens of source code into the chosen syntax tree node.
+ #[cfg(feature = "proc-macro")]
fn parse(self, tokens: proc_macro::TokenStream) -> Result<Self::Output, ParseError> {
self.parse2(tokens.into())
}