Skip to content

Commit 5692530

Browse files
authored
Merge pull request #65 from alexcrichton/proc-macro-feature
Add a feature for linking to `proc-macro`
2 parents 1fd0e8a + 724687b commit 5692530

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ matrix:
1212
script:
1313
- cargo test
1414
- cargo build --features nightly
15+
- cargo build --no-default-features
1516
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
1617
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build --features nightly
1718
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo doc --no-deps

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ unicode-xid = "0.1"
2626
#
2727
# When disabled: emulate the same API as the nightly compiler's proc_macro crate
2828
# but in a way that works on all stable compilers >=1.15.0.
29-
nightly = []
29+
nightly = ["proc-macro"]
30+
31+
proc-macro = []
32+
default = ["proc-macro"]

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#![cfg_attr(feature = "nightly", feature(proc_macro))]
3030

31+
#[cfg(feature = "proc-macro")]
3132
extern crate proc_macro;
3233

3334
#[cfg(not(feature = "nightly"))]
@@ -67,12 +68,14 @@ impl FromStr for TokenStream {
6768
}
6869
}
6970

71+
#[cfg(feature = "proc-macro")]
7072
impl From<proc_macro::TokenStream> for TokenStream {
7173
fn from(inner: proc_macro::TokenStream) -> TokenStream {
7274
TokenStream(inner.into())
7375
}
7476
}
7577

78+
#[cfg(feature = "proc-macro")]
7679
impl From<TokenStream> for proc_macro::TokenStream {
7780
fn from(inner: TokenStream) -> proc_macro::TokenStream {
7881
inner.0.into()
@@ -175,7 +178,7 @@ impl Span {
175178
}
176179

177180
/// This method is only available when the `"nightly"` feature is enabled.
178-
#[cfg(feature = "nightly")]
181+
#[cfg(all(feature = "nightly", feature = "proc-macro"))]
179182
pub fn unstable(self) -> proc_macro::Span {
180183
self.0.unstable()
181184
}

src/stable.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::rc::Rc;
1111
use std::str::FromStr;
1212
use std::vec;
1313

14-
use proc_macro;
1514
use unicode_xid::UnicodeXID;
1615
use strnom::{Cursor, PResult, skip_whitespace, block_comment, whitespace, word_break};
1716

@@ -120,14 +119,16 @@ impl fmt::Display for TokenStream {
120119
}
121120
}
122121

123-
impl From<proc_macro::TokenStream> for TokenStream {
124-
fn from(inner: proc_macro::TokenStream) -> TokenStream {
122+
#[cfg(feature = "proc-macro")]
123+
impl From<::proc_macro::TokenStream> for TokenStream {
124+
fn from(inner: ::proc_macro::TokenStream) -> TokenStream {
125125
inner.to_string().parse().expect("compiler token stream parse failed")
126126
}
127127
}
128128

129-
impl From<TokenStream> for proc_macro::TokenStream {
130-
fn from(inner: TokenStream) -> proc_macro::TokenStream {
129+
#[cfg(feature = "proc-macro")]
130+
impl From<TokenStream> for ::proc_macro::TokenStream {
131+
fn from(inner: TokenStream) -> ::proc_macro::TokenStream {
131132
inner.to_string().parse().expect("failed to parse to compiler tokens")
132133
}
133134
}

0 commit comments

Comments
 (0)