Skip to content

Commit

Permalink
Add a feature for linking to proc_macro.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
staktrace authored and dtolnay committed Mar 31, 2018
1 parent fe58b5a commit 6434beb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "examples/dump-syntax/main.rs"
required-features = ["full", "parsing", "extra-traits"]

[features]
default = ["derive", "parsing", "printing", "clone-impls"]
default = ["derive", "parsing", "printing", "clone-impls", "proc-macro"]
derive = []
full = []
parsing = []
Expand All @@ -25,11 +25,12 @@ visit-mut = []
fold = []
clone-impls = []
extra-traits = []
proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"]

[dependencies]
proc-macro2 = "0.3"
#quote = { version = "0.5", optional = true }
quote = { git = 'https://github.com/dtolnay/quote', optional = true }
proc-macro2 = { version = "0.3", default-features = false }
#quote = { version = "0.5", optional = true, default-features = false }
quote = { git = 'https://github.com/dtolnay/quote', optional = true, default-features = false }
unicode-xid = "0.1"

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -219,6 +220,7 @@ impl TokenBuffer {

/// 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())
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -572,7 +573,7 @@ pub use error::parse_error;
/// #
/// # 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,
Expand Down
2 changes: 2 additions & 0 deletions src/synom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -225,6 +226,7 @@ pub trait Parser: Sized {
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())
}
Expand Down

0 comments on commit 6434beb

Please sign in to comment.