]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #53304 - dtolnay:extend, r=dtolnay
authorbors <bors@rust-lang.org>
Thu, 16 Aug 2018 15:44:30 +0000 (15:44 +0000)
committerbors <bors@rust-lang.org>
Thu, 16 Aug 2018 15:44:30 +0000 (15:44 +0000)
TokenStream::extend

Two new insta-stable impls in libproc_macro:

```rust
impl Extend<TokenTree> for TokenStream
impl Extend<TokenStream> for TokenStream
```

`proc_macro::TokenStream` already implements `FromIterator<TokenTree>` and `FromIterator<TokenStream>` so I elected to support the same input types for `Extend`.

**This commit reduces compile time of Serde derives by 60% (takes less than half as long to compile)** as measured by building our test suite:

```console
$ git clone https://github.com/serde-rs/serde
$ cd serde/test_suite
$ cargo check --tests --features proc-macro2/nightly
$ rm -f ../target/debug/deps/libtest_*.rmeta
$ time cargo check --tests --features proc-macro2/nightly
Before: 20.8 seconds
After: 8.6 seconds
```

r? @alexcrichton

1  2 
src/libproc_macro/lib.rs
src/libsyntax/lib.rs

diff --combined src/libproc_macro/lib.rs
index fec90008c6701ec2d074091d68c8302cf58ca8fd,21c80e14a376bf4b643e4d6cbe541a4596b5d8f4..66afe36e7cb9ad7ff4f5a0ccb8e9194cc347be41
@@@ -31,7 -31,6 +31,7 @@@
         test(no_crate_inject, attr(deny(warnings))),
         test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
  
 +#![cfg_attr(not(stage0), feature(nll))]
  #![feature(rustc_private)]
  #![feature(staged_api)]
  #![feature(lang_items)]
@@@ -180,6 -179,20 +180,20 @@@ impl iter::FromIterator<TokenStream> fo
      }
  }
  
+ #[stable(feature = "token_stream_extend", since = "1.30.0")]
+ impl Extend<TokenTree> for TokenStream {
+     fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I) {
+         self.extend(trees.into_iter().map(TokenStream::from));
+     }
+ }
+ #[stable(feature = "token_stream_extend", since = "1.30.0")]
+ impl Extend<TokenStream> for TokenStream {
+     fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
+         self.0.extend(streams.into_iter().map(|stream| stream.0));
+     }
+ }
  /// Public implementation details for the `TokenStream` type, such as iterators.
  #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
  pub mod token_stream {
diff --combined src/libsyntax/lib.rs
index c48ad0a802cb0470402f99154adea000f12c3e22,7e5b5db5e5a5dbed514c94af4187c1385a74676f..0a42325d2b6ff74a595cfbc0fac2d0ec3a66c9e9
  
  #![feature(crate_visibility_modifier)]
  #![feature(macro_at_most_once_rep)]
 +#![cfg_attr(not(stage0), feature(nll))]
  #![feature(rustc_attrs)]
  #![feature(rustc_diagnostic_macros)]
  #![feature(slice_sort_by_cached_key)]
  #![feature(str_escape)]
  #![feature(unicode_internals)]
 +#![feature(catch_expr)]
  
  #![recursion_limit="256"]
  
@@@ -45,8 -43,6 +45,8 @@@ extern crate serialize as rustc_seriali
  
  use rustc_data_structures::sync::Lock;
  use rustc_data_structures::bitvec::BitVector;
 +pub use rustc_data_structures::small_vec::OneVector;
 +pub use rustc_data_structures::thin_vec::ThinVec;
  use ast::AttrId;
  
  // A variant of 'try!' that panics on an Err. This is used as a crutch on the
@@@ -126,10 -122,17 +126,13 @@@ pub mod util 
      pub mod parser;
      #[cfg(test)]
      pub mod parser_testing;
 -    pub mod small_vector;
      pub mod move_map;
  
 -    mod thin_vec;
 -    pub use self::thin_vec::ThinVec;
 -
      mod rc_slice;
      pub use self::rc_slice::RcSlice;
+     mod rc_vec;
+     pub use self::rc_vec::RcVec;
  }
  
  pub mod json;