Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature for linking to proc-macro #65

Merged
merged 2 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
script:
- cargo test
- cargo build --features nightly
- cargo build --no-default-features
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build --features nightly
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo doc --no-deps
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ unicode-xid = "0.1"
# When disabled: emulate the same API as the nightly compiler's proc_macro crate
# but in a way that works on all stable compilers >=1.15.0.
nightly = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to add nightly = ["proc-macro"] so that default-features = false, features = ["nightly"] can work.


proc-macro = []
default = ["proc-macro"]
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

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

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

#[cfg(not(feature = "nightly"))]
Expand Down Expand Up @@ -67,12 +68,14 @@ impl FromStr for TokenStream {
}
}

#[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()
Expand Down Expand Up @@ -175,7 +178,7 @@ impl Span {
}

/// 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()
}
Expand Down
11 changes: 6 additions & 5 deletions src/stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::rc::Rc;
use std::str::FromStr;
use std::vec;

use proc_macro;
use unicode_xid::UnicodeXID;
use strnom::{Cursor, PResult, skip_whitespace, block_comment, whitespace, word_break};

Expand Down Expand Up @@ -120,14 +119,16 @@ impl fmt::Display for TokenStream {
}
}

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

impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> proc_macro::TokenStream {
#[cfg(feature = "proc-macro")]
impl From<TokenStream> for ::proc_macro::TokenStream {
fn from(inner: TokenStream) -> ::proc_macro::TokenStream {
inner.to_string().parse().expect("failed to parse to compiler tokens")
}
}
Expand Down