Enable rich API on 1.29.0
diff --git a/.travis.yml b/.travis.yml
index 1ada298..d5d7b88 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@
- rust: 1.15.0
- rust: stable
- rust: beta
+ script: cargo test
- rust: nightly
install: rustup target add wasm32-unknown-unknown
script: cargo test --target wasm32-unknown-unknown --no-run
diff --git a/build.rs b/build.rs
index d33aadc..30b5f05 100644
--- a/build.rs
+++ b/build.rs
@@ -17,14 +17,17 @@
None => return,
};
- // Rust 1.30 stabilized the necessary APIs in the `proc_macro` crate
- if minor >= 30 || cfg!(feature = "nightly") {
+ // Rust 1.29 stabilized the necessary APIs in the `proc_macro` crate
+ if minor >= 29 || cfg!(feature = "nightly") {
println!("cargo:rustc-cfg=wrap_proc_macro");
if cfg!(procmacro2_semver_exempt) {
println!("cargo:rustc-cfg=super_unstable");
}
- } else {
+ }
+
+ if minor == 29 {
+ println!("cargo:rustc-cfg=slow_extend");
}
}
diff --git a/src/unstable.rs b/src/unstable.rs
index caf42ce..3e940ca 100644
--- a/src/unstable.rs
+++ b/src/unstable.rs
@@ -210,11 +210,29 @@
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) {
match self {
TokenStream::Nightly(tts) => {
- tts.extend(
- streams
+ #[cfg(not(slow_extend))]
+ {
+ tts.extend(
+ streams
+ .into_iter()
+ .map(|t| TokenStream::from(t).unwrap_nightly()),
+ );
+ }
+ #[cfg(slow_extend)]
+ {
+ *tts = tts
+ .clone()
.into_iter()
- .map(|t| TokenStream::from(t).unwrap_nightly()),
- );
+ .chain(
+ streams
+ .into_iter()
+ .map(TokenStream::from)
+ .flat_map(|t| match t {
+ TokenStream::Nightly(tts) => tts.into_iter(),
+ _ => mismatch(),
+ }),
+ ).collect();
+ }
}
TokenStream::Stable(tts) => tts.extend(streams),
}
@@ -225,7 +243,24 @@
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
match self {
TokenStream::Nightly(tts) => {
- tts.extend(streams.into_iter().map(|stream| stream.unwrap_nightly()))
+ #[cfg(not(slow_extend))]
+ {
+ tts.extend(streams.into_iter().map(|stream| stream.unwrap_nightly()));
+ }
+ #[cfg(slow_extend)]
+ {
+ *tts = tts
+ .clone()
+ .into_iter()
+ .chain(
+ streams
+ .into_iter()
+ .flat_map(|t| match t {
+ TokenStream::Nightly(tts) => tts.into_iter(),
+ _ => mismatch(),
+ }),
+ ).collect();
+ }
}
TokenStream::Stable(tts) => {
tts.extend(streams.into_iter().map(|stream| stream.unwrap_stable()))