Skip to content

Commit 11a33d3

Browse files
authored
Merge pull request dtolnay#128 from dtolnay/rich
Enable rich API on 1.29.0
2 parents d4286c8 + e839e4f commit 11a33d3

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ matrix:
66
- rust: 1.15.0
77
- rust: stable
88
- rust: beta
9+
script: cargo test
910
- rust: nightly
1011
install: rustup target add wasm32-unknown-unknown
1112
script: cargo test --target wasm32-unknown-unknown --no-run

build.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ fn main() {
1717
None => return,
1818
};
1919

20-
// Rust 1.30 stabilized the necessary APIs in the `proc_macro` crate
21-
if minor >= 30 || cfg!(feature = "nightly") {
20+
// Rust 1.29 stabilized the necessary APIs in the `proc_macro` crate
21+
if minor >= 29 || cfg!(feature = "nightly") {
2222
println!("cargo:rustc-cfg=wrap_proc_macro");
2323

2424
if cfg!(procmacro2_semver_exempt) {
2525
println!("cargo:rustc-cfg=super_unstable");
2626
}
27-
} else {
27+
}
28+
29+
if minor == 29 {
30+
println!("cargo:rustc-cfg=slow_extend");
2831
}
2932
}
3033

src/unstable.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,29 @@ impl Extend<TokenTree> for TokenStream {
210210
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) {
211211
match self {
212212
TokenStream::Nightly(tts) => {
213-
tts.extend(
214-
streams
213+
#[cfg(not(slow_extend))]
214+
{
215+
tts.extend(
216+
streams
217+
.into_iter()
218+
.map(|t| TokenStream::from(t).unwrap_nightly()),
219+
);
220+
}
221+
#[cfg(slow_extend)]
222+
{
223+
*tts = tts
224+
.clone()
215225
.into_iter()
216-
.map(|t| TokenStream::from(t).unwrap_nightly()),
217-
);
226+
.chain(
227+
streams
228+
.into_iter()
229+
.map(TokenStream::from)
230+
.flat_map(|t| match t {
231+
TokenStream::Nightly(tts) => tts.into_iter(),
232+
_ => mismatch(),
233+
}),
234+
).collect();
235+
}
218236
}
219237
TokenStream::Stable(tts) => tts.extend(streams),
220238
}
@@ -225,7 +243,24 @@ impl Extend<TokenStream> for TokenStream {
225243
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
226244
match self {
227245
TokenStream::Nightly(tts) => {
228-
tts.extend(streams.into_iter().map(|stream| stream.unwrap_nightly()))
246+
#[cfg(not(slow_extend))]
247+
{
248+
tts.extend(streams.into_iter().map(|stream| stream.unwrap_nightly()));
249+
}
250+
#[cfg(slow_extend)]
251+
{
252+
*tts = tts
253+
.clone()
254+
.into_iter()
255+
.chain(
256+
streams
257+
.into_iter()
258+
.flat_map(|t| match t {
259+
TokenStream::Nightly(tts) => tts.into_iter(),
260+
_ => mismatch(),
261+
}),
262+
).collect();
263+
}
229264
}
230265
TokenStream::Stable(tts) => {
231266
tts.extend(streams.into_iter().map(|stream| stream.unwrap_stable()))

0 commit comments

Comments
 (0)